End of script output before headers

I have written a small script taking the output of a form, formating it and displaying it in a browser. When I run it I get a 500 error with

Error message: 
End of script output before headers: certificate.py

It is similar to an even simpler script which works fine. As far as I can see I am outputing the headers first.

This is my script:


# Import modules for CGI handling 
import cgi, cgitb 

# Create instance of FieldStorage 
form = cgi.FieldStorage() 

# Get data from form fields
# text fields
tname = form.getvalue('tname')
tdate = form.getvalue('tdate')

# textarea
comments = form.getvalue('comments', 'None')

# checkboxes
checkbox1 = ['yes', 'no'][not form.getvalue('certificate')]
checkbox2 = ['yes', 'no'][not form.getvalue('alumni')]

# radio button
grade = form.getvalue('grade', 'Not set')

# dropdown
subject = form.getvalue('subject', 'Not entered')

aoran = ['a', 'an'][grade[0] in 'aeiou']

if ( grade != "ordinary" ):
   grade = grade + ' class honours'

<!doctype html>
<html lang="en-gb">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="certificate.css">
<h2>This is to certify that</h2>''')
print("<h3> %s </h3>" % (tname))
print("<p>has been awarded</p>")
print("<p> %s %s degree</p>" % (aoran, grade))
print("<p>in %s </p>" % (subject))
print("<p>Date: %s </p>" % (tdate))
print("<p>Comments: %s </p>" % (comments))
print("<p>--- for official use ---<br>"
print("certificate: %s; alumni: %s </p>" % (checkbox1, checkbox2))

Any ideas where I’m going wrong?

Edit: Okay, it was due to a syntax error. I guess the syntax error would have been output before the headers but I didn’t get to see it!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.