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:
print "Content-type: text/html\n\n";
print "<title>CGI Test</title>";
print "<p>Test page using Python</p>";
[Sat May 19 09:11:38 2012] [error] [client 184.108.40.206] File does not exist: /home/elkuzu/public_html/404.shtml
[Sat May 19 09:11:38 2012] [error] [client 220.127.116.11] File does not exist: /home/elkuzu/public_html/favicon.ico
[Sat May 19 09:11:37 2012] [error] [client 18.104.22.168] File does not exist: /home/elkuzu/public_html/500.shtml
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 a Unix-like system, The line endings in the program file must be Unix style line endings. This is important because the web server checks the first line of the script (called shebang) and tries to run the program specified there. It gets easily confused by Windows line endings (Carriage Return & Line Feed, also called CRLF), so you have to convert the file to Unix line endings (only Line Feed, LF). This can be done automatically by uploading the file via FTP in text mode instead of binary mode, but the preferred way is just telling your editor to save the files with Unix line endings. Most editors support this.
On Windows (ie Notepad) they're represented as (CR LF, or
\r\n), whereas on unix they're (LF or
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