简体   繁体   English

Python Apache本地/内部服务器错误?

[英]Python Apache local/internal server error?

I am creating HTML form and using Python to code it. 我正在创建HTML表单并使用Python对其进行编码。 I have installed Apache version2.2 and Python version 2.6. 我已经安装了Apache版本2.2和Python版本2.6。 Here is the code: 这是代码:

#!C:\Python26\Python.exe -u

#import cgi modules
import cgi

#create instances of field storage
form = cgi.FieldStorage()

#get data from the 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>"

The code I have written gives me an internal error. 我编写的代码给了我一个内部错误。 But, when I remove the following lines it runs fine. 但是,当我删除以下几行时,它运行正常。

#import cgi modules
    import cgi

    #create instances of field storage
    form = cgi.FieldStorage()

    #get data from the fields
    first_name = form.getvalue('first_name')
    last_name  = form.getvalue('last_name')

I edited the httpd config file and added lines: 我编辑了httpd配置文件并添加了以下行:

AddHandler cgi-script .cgi .py .pl AddHandler cgi-script .cgi .py .pl

ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/" ScriptAlias / cgi-bin /“ C:/程序文件(x86)/ Apache Software Foundation / Apache2.2 / cgi-bin /”

Why is internal error message being displayed when the lines are added? 添加行后,为什么会显示内部错误消息? And, I am new to building HTML forms in Python. 而且,我是第一次使用Python构建HTML表单。 Suggestions on tutorials on HTML form using Python for Windows would be really helpful. 有关使用Windows版Python的HTML表单教程的建议确实很有帮助。 Thanks. 谢谢。

PS: The files containing script are located in cgi-bin Apache folder. PS:包含脚本的文件位于cgi-bin Apache文件夹中。

Something is definitely wrong is you subtracted those lines, and it still ran. 绝对有问题的是您减去了这些行,它仍然运行了。 print "<h2>Hello %s %s</h2>" % (first_name, last_name) in your HTML body should raise an exception, given that they are not defined yet. 在HTML正文中print "<h2>Hello %s %s</h2>" % (first_name, last_name)应该引发异常,因为尚未定义它们。

Please post the bits of your error.log for the Internal Server Error. 请张贴您的error.log的内部服务器错误位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM