I’m using hostgator and they swear that python is supported, but I’ve yet to see one working python script. I’ve tried several scripts, my latest one is the one they give on their website:
#!/usr/bin/python
print "Content-type: text/html\n\n";
print "<html><head>";
print "<title>CGI Test</title>";
print "</head><body>";
print "<p>Test page using Python</p>";
print "</body></html>";
I’m getting an Internal Server Error:
http://elkuzu.com/cgi-bin/test.py
The file has 755 permissions, so does the folder cgi-bin. They refused to help me with what they call “coding” problems… but with all that I’ve tried and received nothing but Internal Server Errors, I’m thinking the problem is with them. Anyone know what could be wrong?
Error Logs:
[Sat May 19 09:11:38 2012] [error] [client 74.129.48.242] File does not exist: /home/elkuzu/public_html/404.shtml
[Sat May 19 09:11:38 2012] [error] [client 74.129.48.242] File does not exist: /home/elkuzu/public_html/favicon.ico
[Sat May 19 09:11:37 2012] [error] [client 74.129.48.242] File does not exist: /home/elkuzu/public_html/500.shtml
I’ve talked with my host (hostgator) and they’ve turned it into a ticket, which makes me think that something is up on their end.
There is documentation on how to use Python as a CGI.
In your case, the issue was the line endings. They’re the hidden character at the end of each line.
On Windows (ie Notepad) they’re represented as (CR LF, or
\r\n), whereas on unix they’re (LF or\n).In Notepad++, you can view line endings as symbols like so: View -> Show Symbol -> Show End of Line
To replace windows linebreaks with unix ones, you can use: Search -> Replace…
In the replace dialogue, find
\r\n, and replace them with\n. Ensure the Extended Search mode is selected.Alternatively, you can use Edit -> EOL Conversion -> UNIX Format