Python as CGI and Error 500, Internal Server Error
If you have this problem on *nix systems, these are the things to look for:
1 - Make sure your line breaks are \n not \r\n you can set this in almost all editors, you will have to either select *nix like line breaks or \n somewhere in your editor preferences.
2 - After the first step you will have to make sure that your FTP client uploads the files in ASCII format and this will insure that \n will stay \n.
3 - If it still doesn’t work, make sure your Python script’s permissions are 755. You can try:
chmod 755 your_python_script.py
Or use your FTP client to fix this. (Refer to it’s documentation but usually you can right click on the file, on your server and click properties)
4 - If you still have the problem, you will have to have the right shebang line in the beginning of your script, the most common one is:
#!/usr/bin/env python
If this doesn’t work try:
#!/usr/bin/python
Or:
#!/usr/local/bin/python
Note that, this must be the first line
5 - If none of these worked and you have root access to your server, try:
tail -f /usr/local/apache/logs/error_log (Note that, the path to Apache error log might be different on your server)
And look for the error message associated with your request.
6 - If you still can’t figure it out, write to your hosting company and ask them.
I hope this helps
Archived under Annoying Stuff, Python Comments

