[英]Executing Python cgi files in Apache on Windows
I am trying to run a very simple "Hello World" program with Apache. 我正在尝试使用Apache运行一个非常简单的“ Hello World”程序。 However, Apache returns a 500 Internal Server Error when it tries to execute my python file.
但是,Apache在尝试执行我的python文件时返回500 Internal Server Error。 I've read several similar topics on here and tried the suggestions, no luck.
我在这里阅读了几个类似的主题,并尝试了建议,但没有走运。 Things I have tried:
我尝试过的事情:
The tools I am using include: 我使用的工具包括:
My code: The HTML File (in the htdocs folder in the Apache folder): 我的代码: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>
The python file (in the cgi-bin folder): 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>")
I figured it out. 我想到了。
In my shebang line, instead of: 在我的排行中,而不是:
#!C:/Users/MyName/workspace/Flask/flask/Scripts
I should have: 我应该:
#!C:/Users/MyName/workspace/Flask/flask/Scripts/python.exe
I thought my shebang should have a path to where the python interpreter lives, I didn't realize I needed the actual full path of the interpreter. 我以为我的shebang应该有一条通往python解释器的路径,但我没有意识到我需要解释器的实际完整路径。
It is working now. 现在正在工作。
So to recap, if you are having this issue after following these instructions: http://editrocket.com/articles/python_apache_windows.html Make sure that if you are using Windows the path is the full absolute path from the C:/ drive to the python.exe executable. 综上所述,如果按照以下说明操作后出现此问题: http : //editrocket.com/articles/python_apache_windows.html确保使用Windows时,该路径是从C:/驱动器到python.exe可执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.