Python CGI Premature end of script error depending on script parameters.

Posted by nickengland on Stack Overflow See other posts from Stack Overflow or by nickengland
Published on 2010-04-19T14:35:21Z Indexed on 2010/04/19 14:43 UTC
Read the original article Hit count: 237

Filed under:
|

I have a python script which should parse a file and produce some output to disk, as well as returning a webpage linking to the outputted files. When run with a file posted from the HTML form I get no HTML output back, just a 500 error page and the error_log contains the line:

[Mon Apr 19 15:03:23 2010] [error] [client xxx.xxx.121.79] Premature end of script headers: uploadcml.py, referer: http://xxx.ch.cam.ac.uk:9000/

However, the files which the script should be saving are indeed saved to disk.

If I run it without any arguments, the script returns the correct HTML indicating no file was parsed.

All the information I have found on the web about Premature end of script headers implies it is due to either a missing header, or lack of permissions on the python script but neither can apply to me.

The first lines of the script are:

#!/home/nwe23/bin/bin/python
import cgitb; cgitb.enable()
import cgi
import pybel,openbabel
import random
print "Content-Type: text/html"
print

so when run, I can see no way for it to fail to output the header, and it DOES output the header when run without a file to parse, but when given a file produces the error(but still parsed the file and saves the output to disk!).

Does anyone know how this is happening and what can be done to fix it?

I have tried adding wrongly-indented gibberish (such as foobar) at various points in the file, and this results in adding an indent error to the error_log wherever it is, even if its the very last line in the script. The Premature script headers error remains though. Does this mean the script is executing all the way through?

© Stack Overflow or respective owner

Related posts about python

Related posts about cgi