CGI

ID #120

Importing the Python cgi module doesn't work.

Applies to: Grid System

The following code is how you import the python cgi module:

#!/usr/bin/python2.1
import cgi

If that is giving you a traceback error, then you are probably trying to run it on the command line, which is not supposed to work.

"Unfortunately, a CGI script will generally not run when you try it from the command line, and a script that works perfectly from the command line may fail mysteriously when run from the server. There's one reason why you should still test your script from the command line: if it contains a syntax error, the Python interpreter won't execute it at all, and the HTTP server will most likely send a cryptic error to the client."


Last update: 2010-09-29 16:59
Author: FAQ Admin
Revision: 1.2

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 0 (0 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ

Comment of Anonymous:
An example Python cgi script that imports MySQLdb (just make sure the file permissions on this script are 755:

#!/usr/bin/python

import MySQLdb

def main():
print "Content-type: text/html\n"
print "hello, anonymous!"

main()


Added at: 2002-05-03 19:32

Comment of Anonymous:
An example Python CGI script (with file permission chmod 755):

#!/usr/bin/python

import cgi

def main():
print "Content-type: text/html\n"
print "hello!"

main()
Added at: 2002-05-03 19:33

Comment of Anonymous:
The code below successfully establishes a database connection: make sure to replace db login with your username and password.
#!/usr/bin/python
import MySQLdb
host = 'db.modwest.com'
user = 'yourUsername'
passwd = 'yourPasswd'
db = 'yourDB'

MySQLdb.connect(host = host, user = user, passwd = passwd, db = db)
Added at: 2002-06-18 18:21