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

时间:2010-06-19 21:33:02

标签: python html apache2 cgi-bin apache2.2

我正在创建HTML表单并使用Python对其进行编码。我已经安装了Apache version2.2和Python 2.6版。这是代码:

#!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>"

我写的代码给了我一个内部错误。但是,当我删除以下行时,它运行正常。

#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')

我编辑了httpd配置文件并添加了行:

AddHandler cgi-script .cgi .py .pl

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

为什么添加行时会显示内部错误消息?而且,我是在Python中构建HTML表单的新手。使用Python for Windows的HTML表单教程的建议将非常有用。 感谢。

PS:包含脚本的文件位于cgi-bin Apache文件夹中。

1 个答案:

答案 0 :(得分:0)

有些东西肯定是错误的,你减去那些线,它仍然运行。在你的HTML正文中print "<h2>Hello %s %s</h2>" % (first_name, last_name)应该引发异常,因为它们尚未定义。

请发布您的error.log中的内部服务器错误。