Home
 

Customer Support

Search for keywords:

Browse by category:

Importing the Python cgi module doesn't work.

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."

User-Contributed Notes

add a note
03-May-2002 19:32
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 "<h2>hello, anonymous!</h2>"

main()


03-May-2002 19:33
An example Python CGI script (with file permission chmod 755):

#!/usr/bin/python

import cgi

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

eddiesobenes -at- netscape.net
18-Jun-2002 18:21
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)

add a note

Related Questions:


How do I use sendmail with perl?

How do I use cgi scripts?

My formmail.pl script from Matt's Script Archive doesn't work.

Why does Sbox say "no such file or directory" but the files are there?

What Perl modules are installed?

Do you offer CGI? What scripts can I install?

I can't get the python socket module to work?

What is the path to perl or some other program?

Why do I get: Sbox error file is world writable?

Sendmail does not work or does not accept my optional arguments.

How do I use MySQL with Python?

What version of Python do you support and what modules are available?

Why do I get: Sbox Error exec of [some script] failed (Exec format error)?

Why do I get: Sbox error file not world executable?

Why do I get: Sbox error the directory containing [some script] is world writable?

Why do I get: Sbox Error exec of [some script] failed (Permission denied)

Why do I get: Sbox error: cannot run suid scripts

Why do I get: Sbox Error exec of [some script] failed (Resource temporarily unavailable)

Browse Categories:

Getting Started, FTP, Telnet/SSH, Moving Domains, E-mail, Traffic Reports, Mailing Lists, Apache, PHP, CGI, Other Server-Side Scripting, MySQL Database, Imaging Libraries, Other Software, Billing & Terms, Control Panel, E-commerce, Pre-Sales


Tiny Modwest Logo         Copyright 2000-2008 by Modwest, Inc.          About Us    |    Blog    |    Jobs    |    Web Design    |    Contact Us