我的Python脚本出现500内部服务器错误,问题不明
下面是一个Python脚本,它的作用是打开一个.ss文件(空格分隔向量),并根据这个文件的内容生成一个调查页面。这个文件里包含了调查的名称和要问的问题。作为我们作业的一部分,每个小组成员都需要在自己的页面上运行这个脚本(叫做survey.py)。但是,当我尝试在我的页面上运行survey.py时,出现了500内部服务器错误。查看错误日志时,发现上面写着“脚本头部提前结束:survey.py”。我不太明白这是什么意思,有谁能帮帮我吗?
以下是代码:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
new = open("survey.ssv", "r")
lines = new.readlines()
i = 0
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Take-a-Survey!</title>"
print "</head>"
print "<body bgcolor='white' text='black'>"
print "<center>"
print "<h1>Take Survey Page</h>"
print "</center>"
print "Information."
print "<br><br>"
for line in lines:
if i == 0:
print "Survey Title:<br>%s" % line
print "<br><br>"
print '<form action="results.py" method="post">'
else:
print "Question %d:<br>%s" % (i, line)
print '<br>'
print '<input type="radio" value="stronglyAgree" name="demFeels%d"></input>' % i
print 'Strongly agree'
print '<br>'
print '<input type="radio" value="agree" name="demFeels%d"></input>' % i
print 'Agree'
print '<br>'
print '<input type="radio" value="disagree" name="demFeels%d"></input>' % i
print 'Disagree'
print '<br>'
print '<input type="radio" value="stronglyDisagree" name="demFeels%d"></input>' % i
print 'Strongly disagree'
print '<br><br>'
i = i + 1
print '<input type="submit" name="results" value="Submit">'
print '</form>'
print '</body>'
print '</html>'
new.close()
print '</form>'
1 个回答
1
在内容类型的头信息后面,添加以下内容:
print # blank line, end of headers
你需要通过这个空行来正确地表示你已经结束了头信息的输出。