mardi 30 juin 2015

Premature end of script headers for unknown reason

Whenever I call the cgi script below by submitting a form to it I get an internal server error and the server log shows the line: Premature end of script headers: LoopFinderRetrieval.cgi, referer: http://ift.tt/1eY3f7g

In short, the cgi file is meant to go to the folder indicated by a run-ID, given at the time of submission, open and read a file called JobStatus.txt, and then perform an action based on the result. This can either be returning a specific error to the user, or giving them their results. As I understand it, the error I'm seeing would be caused if I was, for example omitting the line:

"Content-type:text/html\r\n\r\n"

but the line is present, and another CGI script using the exact same PrintHeader() and PrintFooter() functions on the same server is running without error. Can anybody see any clear errors that might be causing this? If not, what I've read indicates that this might be a permissions issue. In that case I'll have to contact the administrators and have it fixed, but I don't want to do that unless I know it's the problem. Thanks.

#!/usr/bin/python2.6

# Import modules for CGI handling 
import cgi, cgitb
import os 
cgitb.enable()

#Functions to automatically print HTML headers and footers.
def PrintHeader():
    print "Content-type:text/html\r\n\r\n"
    print "<html>"
    print "<head>"
    print "<title>LoopFinder Running</title>"
    print "</head>"
    print "<body>"
def PrintFooter():
    print "</body>"
    print "</html>"

# Create instance of FieldStorage 
form = cgi.FieldStorage() 
ID_Number = form.getvalue('IDNum')

with open('/loopfinder_data/RunData/%s/JobStatus.txt' % ID_Number, 'r') as pre_textfile:
    textfile = pre_textfile.read()
    if textfile[0] == 'Running':
        PrintHeader()
        print '<h2>Your run is not complete. Please check back later.</h2>'
        PrintFooter()
    if textfile[0] == 'Stopped':
        PDBID = textfile[3]
        if textfile[1] == 'PDBError':
            PrintHeader()
            print '<h2>We were unable to download the PBDID you entered, which was %s</h2>' % PDBID
            print '<h2>Please check that this PDBID exists before trying again.</h2>'
            PrintFooter()
        elif textfile[1] == 'ChainCountError':
            PrintHeader()
            print '<h2>We were unable to either download or open the PBDID you entered, which was %s</h2>' % PDBID
            print '<h2>Please check that this PDBID exists before trying again.</h2>'
            PrintFooter()       
        elif textfile[1] == 'SingleChainError':
            PrintHeader()
            print '<h2>It appears that your PDB structure of interest contains only one chain.</h2>'
            print '<h2>LoopFinder requires a multi-chain interface from which to calculate energy values.</h2>'
            PrintFooter()
        elif textfile[1] == 'LoopFinderError':
            PrintHeader()
            print '<h2>LoopFinder experienced an unknown error while analyzing your PDB file.</h2>'
            print '<h2>Leave a comment including your run ID and we will try to solve this issue.</h2>'
            PrintFooter()   
        elif textfile[1] == 'PyRosettaError':
            PrintHeader()
            print '<h2>PyRosetta experienced an unknown error while analyzing your PDB file.</h2>'
            print '<h2>Leave a comment including your run ID and we will try to solve this issue.</h2>'
            PrintFooter()                   
    if textfile[0] == 'Completed':
        PrintHeader()
        print '<a href="http://<url_redacted>/loopfinder_data/RunData/%s/results/%s_Results.zip">\
Click here to download your results.</a>' % (ID_Number,ID_Number)
        PrintFooter()




Aucun commentaire:

Enregistrer un commentaire