Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Premature end of script headers Error in python cgi script

Tags:

python

apache

cgi

I am running to a problem a vps I recently moved to. I am trying to run a python cgi script, but I am getting an apache Premature end of script headers Error.

(I chmod +x the script file)

The script is pretty simple:

#!/usr/bin/env python                                      
import cgi, cgitb
cgitb.enable()

print "Content-type: text/html"
print "<html><body>hello scritp</body></html>"

Now if I name the script as test**.py** it runs fine on server. But if I do it the correct way, calling it test**.cgi** I receive a Internal Server Error.

I run the script from the terminal

./test.cgi

I get no errors

 Content-type: text/html
 <html><body>hello scritp</body></html>

Did anyone encountered before this issue? And a solution for it? :) Cheers

like image 655
MrCastro Avatar asked Apr 19 '14 13:04

MrCastro


2 Answers

change the header as:

print "Content-type: text/html\n\n"
like image 93
user956424 Avatar answered Oct 16 '22 07:10

user956424


There must be at least an empty line between HTTP headers and body. So

print "Content-type: text/html\n" will work just fine

Reference: Wikipedia

like image 34
Abdul Rauf Avatar answered Oct 16 '22 09:10

Abdul Rauf