I'm trying to get Python 2.6 to communicate with MySQL Server 5.1, under Windows XP, but I keep getting a strange error, "SystemError: NULL object passed to Py_BuildValue":
>>> 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\开发者_StackOverflowcursors.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
I thought it might be a character set problem, but I've tried setting and setting MySQL as UTF-8, and it hasn't made a difference.
I guess there must be a problem with python-mysql. Can anyone help?
UPDATE
OK, python-mysql under windows is a bit of a nightmare, particularly with Python 2.6 it seems. Rather than installing python-mysql with pip, use this installer instead. That fixed it.
Something wrong with MySQLdb part written in C. According to errors message it tries to pass NULL where pointer to object is expected. It's probably a bug in MySQLdb, unless you are using some broken build. What version are you using? Try to download latest stable version of MySQLdb for exactly your python version and reinstall it. Try installing previous version. And fill in bug report if latest version doesn't work.
This and this reports are probably relevant to you error. According to them you mysql returns some error that triggers a bug in MySQLdb. Unfortunately it's not so easy to discover what this error is.
精彩评论