python cgi errors and setup

Started by
3 comments, last by TravisWells 17 years, 9 months ago
Now I have just gotten myself a nice new web host, that suport python. I want to use python to write the backend of my site. Now the problem arives, I cant get a single script to work.. *I am pretty fluent in python (from a win32 perspetive only thought) (note the server ownly suports python thought cgi not mod_python. :( ) Anyway. I get a 500 error everytime that I try to run a .py file in my cgi-bin. The file is chmod'ed 755 (tried with 777 no luck) Here is the example:

#!/usr/bin/env python

# Headers and an extra blank line
print 'Content-type: text/html'
print

# Body
print '<html><body><p>Hello World!</p></body></html>'

Now I belive that the first line is the cause to all these problems. Its suposed to point to the python runtime? After looking around the net I saw many diffrent 1lines. Among: #!/usr/bin/python #!/usr/local/bin/python I tried all these to no more success. I get a 500 internal server error each time. Is there any other locations that the webhost might have hidden the python runtime? Or is this not the cause of the problems? Please give me a hand here.
- Me
Advertisement
If you can telnet or ssh to the host, try typing "which python".
I do not have telnet or ssh connectivity to the server.
Any others?
- Me
Write a non-Python (eg. sh or bash) CGI script to return the output of "which python" [smile]
Another thing to try:
Make sure your file has unix (\n only) line endings. If saving on windows you'll get \r\n and that'll prevent your script from running (Python doesn't care about this, but the #! line is interpreted before python even starts)

Also, make sure the #! line is at the very beginning of your script (No lines before it, even comments or blank lines)

Have you checked your host's site? They may have a FAQ showing the location of the python binary.

This topic is closed to new replies.

Advertisement