Looks like server problem. Contact your server support.
MySQLDB import error in CGI python Script
Question
I write following script in cgi-bin while if I run this script from browser by entering URL then script gives an 500 internal server
error.
#!/usr/bin/python
import MySQLdb
import cgi
print "Content-type: text/html"
print
print "<html>"
print "<head>"
print "<title>Listing</title>"
print "</head>"
print "<body>"
print "<h2>listing</h2>"
db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="DB_name")
cur = db.cursor()
cur.execute("select * from table")
rows = cur.fetchall()
for row in rows:
print row[0]
print "</body>"
print "</html>"
If I remove the DB connection lines then its working fine, but if I just add import MySQLdb
then I get 500 internal server error.
Out put of
import sys
for p in sys.path:
print p + "<br/>"
/home/database/public_html/cgi-bin
/usr/lib64/python26.zip
/usr/lib64/python2.6
/usr/lib64/python2.6/plat-linux2
/usr/lib64/python2.6/lib-tk
/usr/lib64/python2.6/lib-old
/usr/lib64/python2.6/lib-dynload
/usr/lib64/python2.6/site-packages
/usr/lib64/python2.6/site-packages/gtk-2.0
/usr/lib/python2.6/site-packages
Operating system is Redhat.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow