下面是一个python脚本,用于打开.ssv文件(空格分隔向量)并根据.ssv文件的内容生成调查页面。该文件包含调查名称以及调查中要询问的问题。作为我们任务的一部分,每个组成员都应该托管这个脚本(称为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>'
答案 0 :(得分:1)
在内容类型标题行之后添加:
print # blank line, end of headers
您需要通过此空行正确发出结束信号的信号。