我試圖讓Python 2.6中使用MySQL服務器5.1,在Windows XP下溝通下會失敗,但我不斷收到一個奇怪的錯誤, 「關於SystemError:空對象傳遞給Py_BuildValue」:的Python/MySQL的的Windows
>>> import MySQLdb as mysql
>>> db = mysql.connect(user = "root", passwd="whatever", db="mysql", host="localh
ost")
>>> cu = db.cursor()
>>> cu.execute("show tables")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\dirr\lib\site-packages\MySQLdb\cursors.py", line 173, in execu
te
self.errorhandler(self, exc, value)
File "C:\ dirr\lib\site-packages\MySQLdb\connections.py", line 36, in de
faulterrorhandler
raise errorclass, errorvalue
SystemError: NULL object passed to Py_BuildValue
我認爲這可能是一個字符集問題,但我試過設置和設置MySQL爲UTF-8,並沒有什麼區別。
我想python-mysql一定有問題。誰能幫忙?
UPDATE
OK,蟒蛇,MySQL的windows下是有點一場噩夢,特別是與Python 2.6看起來。而不是使用pip安裝python-mysql,而是使用this installer。這解決了它。