无法在本地主机上执行简单的python脚本

时间:2018-08-16 00:35:13

标签: python apache cgi

我正在尝试在本地主机上执行简单的python脚本。

脚本位于htdocs-> test.py

脚本为:

#!C:\Users\First Last\AppData\Local\Programs\Python\Python37-32\python\python.exe
print("Single Quotes")

在浏览器中点击http:\ localhost \ test.py之前,我启动了apache服务器。还在文件末尾添加了以下几行:httpd.conf:

AddHandler cgi-script .py ScriptInterpreterSource注册表严格

但是当我在浏览器中点击http:\ localhost \ test.py时,它仍然显示错误:

Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.7

我在互联网上阅读了许多文章/帖子来解决此问题,但仍然无法解决。请帮忙。

1 个答案:

答案 0 :(得分:0)

您还需要输出HTTP响应标头。

例如:

#!C:\Users\First Last\AppData\Local\Programs\Python\Python37-32\python\python.exe
print("Content-type: text/plain\n")
print("Single Quotes")