You Are Here Home > Python as CGI and Error 500, Internal Server Error

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 :)

Python as CGI and Error 500, Internal Server Error
Filed under: Annoying Stuff, Python   Posted by: Codehead on November 10, 2008

Disclaimer
1 - Use the information provided here at your own risk.
2 - You may not republish this content without prior written consent.




2 Comments »

  1.  

    I found this useful and wrote up a small article on my site about my trial and error approach to resolving my error 500 nightmare! Thanks for the thoroughness!

    Comment — December 5, 2009 @ 10:22 pm

  2.  

    thank you your information is helpfull

    Comment — January 26, 2010 @ 7:05 am

RSS feed for comments on this post. TrackBack URL

Leave a comment