Wells Oliver - 2010-04-22

I can't figure out why this is happening. The following query goes into a
UTF8-encoded InnoDB table:

REPLACE INTO transaction (orig_asset_type,player,team_id,trans_date_cd,player_id,name_sort,note,type_cd,conditional_sw,from_team,effective_date,type,transaction_id,orig_asset,final_asset_type,from_team_id,final_asset,resolution_cd,trans_date,resolution_date,name_display_last_first,name_display_first_last,team) VALUES ('PL', 'Brad Lidge', 143, 'D', 400058, 'LIDGE, BRAD', 'Philadelphia Phillies placed RHP Brad Lidge on the 15-Day disabled list retroactive to March 26, 2010. Recovering from November 2009 right elbow surgery.', 'SC', NULL, NULL, '2010-03-26T00:00:00', 'Status Change', 35236, 'Player', NULL, NULL, NULL, 'FIN', '2010-04-01T00:00:00', '2010-03-26T00:00:00', 'Lidge, Brad', 'Brad Lidge', 'Philadelphia Phillies')

When I run this query from a python script using MySQLdb, it throws:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "py_mlb/transactions.py", line 54, in save
    db.execute(sql, values)
  File "py_mlb/db.py", line 46, in execute
    cursor.execute(sql, values)
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 147, in execute
    charset = db.character_set_name()
_mysql_exceptions.InterfaceError: (0, '')

But when I run the query manually in the MySQL monitor, it works fine. Any
ideas here? The python is very simple:

        for transaction in self:

            values = [None if x == '' else x for x in transaction.values()]
            sql = 'REPLACE INTO transaction (%s) VALUES (%s)' % (','.join(transaction.keys()), ','.join(['%s'] * len(values)))
            db.execute(sql, values)
            db.save()

db being a class that just has a cursor object, which calls execute(sql,
values).