我在 cgi-bin 中编写以下脚本,而如果我通过输入 URL 从浏览器运行此脚本,则脚本会500 internal server
出错。
#!/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>"
如果我删除数据库连接线那么它工作正常,但如果我只是添加import MySQLdb
然后我得到 500 内部服务器错误。
输出
导入系统
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
操作系统是红帽。