Python/MySQL fails under Windows

Posted by AP257 on Stack Overflow See other posts from Stack Overflow or by AP257
Published on 2009-11-20T17:21:25Z Indexed on 2010/03/28 18:03 UTC
Read the original article Hit count: 303

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about mysql