Python problem


#1

I’m having problems getting a CGI script to work with python. If I run the following script (test.cgi), it works fine:

#!/bin/sh
echo Content-Type: text/plain
echo
echo IT WORKS

However if I try to use python (with the same file permissions)

#!/usr/bin/python

causes an internal server error (below). Am I listing python correctly? This seems to be what the knowledgebase recommends.

Any suggestions?

Thanks

  • Lars

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@teachtown.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


#2

Here’s a handy Python CGI test script that I use to make sure I can run Python scripts on a new server and to find out a bit about the configuration of the server. FYI, you can use a .py extension on the file on a DreamHost site; just make sure you chmod 755 the file. Although it reveals in what language your CGI script is implemented, it lets you be lazy like me and FTP files back and forth for quicker debugging on a local machine in an IDE.

#!\usr\bin\python
print "Content-type: text/html"
print
print "

"
import os, sys
print “Python %s” % sys.version
for (x,y) in os.environ.items():
print “%s\t%s” % (x, y)
print “

#3

Not sure why I reversed my slashes in the shebang line. I meant to type:

#!/usr/bin/python
print "Content-type: text/html"
print
print "

"
import os, sys
print “Python %s” % sys.version
for (x,y) in os.environ.items():
print “%s\t%s” % (x, y)
print “