1

I am trying to host a sample program test.py in my sourceforge repository. I uploaded my file from the directory /home/project-web/motiur/cgi-bin/ and then went to motiur.sourceforge.net/cgi-bin/test.py. Unfortunately I got an error that suggests premature end of headers .

The source code of test.py :

#!/usr/local/bin/python
import cgi, cgitb
print "Content-type:text/html\n"
print "<html><body>This is another test</body></html>"

The exact error is:

An error has been encountered in accessing this page. 
  1. Server: motiur.sourceforge.net 
  2. URL path: /cgi-bin/test.py 
  3. Error notes: Premature end of script headers: test.py 
  4. Error type: 500 
  5. Request method: GET 
  6. Request query string: 
  7. Time: 2013-01-12 14:49:39 UTC (1358002179)

BTW, I am using filezilla in windows and had set the file permission to 755, that is everybody can execute the file. This a noob question, a little help will be much appreciated. Thanks.

5
  • @YannisRizos: The error is ; An error has been encountered in accessing this page. 1. Server: motiur.sourceforge.net 2. URL path: /cgi-bin/test.py 3. Error notes: Premature end of script headers: test.py 4. Error type: 500 5. Request method: GET 6. Request query string: 7. Time: 2013-01-12 14:49:39 UTC (1358002179)
    – motiur
    Commented Jan 12, 2013 at 15:09
  • Take a look at the article Premature end of script headers. One thing I noticed that's different is they have an extra newline at the end of the print "Content-type:text/html\n\n".
    – martineau
    Commented Jan 12, 2013 at 17:14
  • @martineau: Sorry , the problem still persists , even after your change .
    – motiur
    Commented Jan 12, 2013 at 17:35
  • See Installing your CGI script on a Unix system in the docs.
    – martineau
    Commented Jan 12, 2013 at 18:40
  • How about #!/usr/bin/env python at the beginning?
    – martineau
    Commented Jan 12, 2013 at 18:43

1 Answer 1

0

Try this:

print 'Content-type: text/html'
print ''
print '<html><body>This is another test</body></html>'

You might need two '\n\n' before the body of the response.

Edit

Then try this:

#!/usr/bin/env python

At the top instead of

#!/usr/local/bin/python
7
  • Sorry the error persists . Is there any problem with the line of code: #!/usr/local/bin/python import cgi, cgitb. By the way my code runs just fine in my localhost . I am suspecting the linking of the python interpreter and my access link of my test.py file .
    – motiur
    Commented Jan 12, 2013 at 17:08
  • Sorry , I am still getting premature end of script headers error . You can visit the site at motiur.sourceforge.net/cgi-bin/test.py to see the error .
    – motiur
    Commented Jan 13, 2013 at 4:16
  • Is sourceforge using python 3? If so, you'll need parentheses around the strings. Commented Jan 13, 2013 at 4:49
  • Nope , its using python 2.4.3 ; strangely enough !
    – motiur
    Commented Jan 13, 2013 at 6:08
  • Then I would try deploying elsewhere. 2.4.3 is so ancient no one can reasonably support it. Someone should yell at SourceForge for this. Commented Jan 13, 2013 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.