ifiore
ifiore

Reputation: 470

Getting a 500 internal server error for my python script, unsure what the issue is

below is a python script that is made to open a .ssv file (space separated vector) and generate a survey page based on the contents of the .ssv file. the file contains the survey name as well as questions to be asked in the survey. as part of our assignment, each group member is supposed to host this script (called survey.py). however, when I attempt to run survey.py on my page, i get a 500 internal server error. looking at the error log, it says "Premature end of script headers: survey.py" I am unsure what this means, can anyone help?

Here is the code:

     #!/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>'

Upvotes: 0

Views: 964

Answers (1)

Vlad Lyga
Vlad Lyga

Reputation: 1143

just after the Content type header line add:

print                               # blank line, end of headers

You need to properly signal that you ended printing headers by this empty line.

Upvotes: 1

Related Questions