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
change the header as:
print "Content-type: text/html\n\n"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With