Python CGI Premature end of script error depending on script parameters

I have a python script that needs to parse a file and produce some output to disk, and also return a web page associated with the output files. When you run the file submitted from the HTML form, I don't get HTML output back, only 500 error pages, and the error_log file 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 saved by the script are indeed saved to disk.

If I run it without any arguments, the script will return correct HTML until the file is parsed.

All the information I have found on the internet about invalid end script headers implies that it is due to either a missing header or a lack of permissions on the python script, but none of these can apply to me.

The first lines of the script:

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

      

so on startup I see no way for it to fail to output the header, and it outputs the header on startup without a file to parse, but when the given file throws an error (but still parsed the file and save the output to disk!).

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

I tried to add erroneously indented gibberish (like foobar) at various points in the file and this results in an indented error being added to the error_log wherever it is, even if its the very last line in the script, Premature script headers error. Does this mean the script runs all the way through?

[EDIT] I managed to get it working now, it seems that one of the calls to the external C ++ library via SWIG failed, but no helpful error message came up. I fixed this issue and the script now works correctly.

Surprisingly the only error in the error_log was in the script headers when some remote library call failed. I suppose the danger of calling non-python code? [/ EDIT]

+2


a source to share


1 answer


When the C library receives a segmentation fault or otherwise crashes, the stdout buffer cannot be flushed. Using the -u

Python interpreter option or manually clearing it should resolve "Premature end of script headers", but it won't help with the real problem.



+1


a source







All Articles