作者magicallove (小判)
看板Python
标题[问题] cgi上面 import MySQLdb 无法成功,但是直接执行正常
时间Sat Jul 4 19:44:21 2009
我写了下面这只python程式要来获得MySQL里面的资料
#!/usr/bin/python
#coding:utf-8
import MySQLdb
conn = MySQLdb.connect(host="x.x.x.x",user="xx",passwd="xx",db="xx")
cursor = conn.cursor()
cursor.execute("select * from rule")
result = cursor.fetchall()
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
print "<html>"
print "<head>"
print "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"
print "<title> Python import MySQLdb</title>"
print "</head>"
print "<body>"
for record in result:
print record[0]
print "</body>"
如果我直接在 console 里面 python sql.py的话可以正确获得资料
但是放到网站上面想要作成cgi来用的时候就会出现
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator,
[email protected] and inform them of
the time the error occurred, and anything you might have done that may have
caused the error.
More information about this error may be available in the server error log
错误讯息蛮多的,我贴在这边。
http://sites.google.com/site/iwhiori/home/python-mysqldb-error
总而言之我想要用 python 在网页上面读取资料库资料
咕狗了超过八个小时!!还是找不到答案...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.174.37.8
1F:→ sbrhsieh:错误讯息不是说了没有权限存取档案夹:/nonexistent? 07/04 20:27
2F:推 shaopin:你有权限execute和读DB,user of CGI没有... 07/05 01:30
3F:→ magicallove:那谁是use of CGI ? 07/05 01:36
4F:→ iincho:通常是apache... 07/05 10:48