![](/img/trans.png)
[英]Error with executing Python files in cgi-bin (have tried enabling CGI Scripts in Apache)
[英]Executing Python cgi files in Apache on Windows
我正在尝试使用Apache运行一个非常简单的“ Hello World”程序。 但是,Apache在尝试执行我的python文件时返回500 Internal Server Error。 我在这里阅读了几个类似的主题,并尝试了建议,但没有走运。 我尝试过的事情:
我使用的工具包括:
我的代码:HTML文件(在Apache文件夹的htdocs文件夹中):
<form action="/cgi-bin/hello_get.py" method="post">
First Name: <input type="text" name="first_name"> <br />
Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>
python文件(在cgi-bin文件夹中):
# Note that I tried this without the C:/ also
#!C:/Users/MyName/workspace/Flask/flask/Scripts
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print("Content-Type:text/html\r\n\r\n")
print("<html>")
print("<head>")
print("<title>Hello - Second CGI Program</title>")
print("</head>")
print("<body>")
print("<h2>Hello %s %s</h2>" % (first_name, last_name))
print("</body>")
print("</html>")
我想到了。
在我的排行中,而不是:
#!C:/Users/MyName/workspace/Flask/flask/Scripts
我应该:
#!C:/Users/MyName/workspace/Flask/flask/Scripts/python.exe
我以为我的shebang应该有一条通往python解释器的路径,但我没有意识到我需要解释器的实际完整路径。
现在正在工作。
综上所述,如果按照以下说明操作后出现此问题: http : //editrocket.com/articles/python_apache_windows.html确保使用Windows时,该路径是从C:/驱动器到python.exe可执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.