I’m having some trouble with MySQLdb when using it in a CGI script. I’m on OSx and running off a local host.
Basically, when I run my code from the terminal it runs fine, but when I run it from a browser, it executes everything up until the import MySQLdb line, and nothing after.
For example:
#!/usr/bin/python
print "Content-Type: text/html\n"
print "abc"
In the browser and the terminal, this prints out abc.
But the following:
#!/usr/bin/python
print "Content-Type: text/html\n"
print "abc"
import MySQLdb
print "123"
In the terminal prints out abc and 123, but in the browser it just prints out abc.
It seems that it’s having a problem with the import MySQLdb line, but I can’t see any errors.
Would anyone have any ideas?
To narrow down the problem, I’d look in two places. The first would be your webserver’s error log. I’m not sure where that is on OS X, but on e.g. Red Hat it can be found in
/var/log/httpd/error_log. Usetail -fto watch the error log as you submit your HTTP request:The other thing you can look into is Python’s
cgiandcgitbmodules. The former will save you having to reinvent wheels, and the latter will give you tracebacks in your browser.