Python/MySQL fails under Windows
- by AP257
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\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
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.