July 28th, 2004, 04:22 PM
ValueError with times in MySQLdb
I'm having a problem with MySQLdb. I get the error:
ValueError: invalid literal for int(): 7-
This only happens on one machine using python2.2 and MySQLdb 0.9.1 or using python2.3 and MySQLdb 1.0.0 -- MySQL vers 4.0.20
On another machine it works with python2.3 and MySQLdb 0.9.2., MySQL vers 4.0.18
mxDateTime 2.0 on both systems.
I'm guessing it's parsing a time string from the db to turn it into a DateTime object and is getting '7-' instead of '07' for the month part. But I have no idea what to do about it. Can anyone help?
July 28th, 2004, 05:57 PM
Still same conditions, but I've narrowed it down to a MySQL timestamp field.
July 29th, 2004, 04:02 AM
What does the timestamp being returned by MySQL look like? At first glance it looks like Python is having problems type-casting the timestamp to an int(). Maybe you could post a little code?
FYI you can see if the timestamp is being returned as a Python object by printing it (assuming that the object doesn't have a __str__() method) or using the type() or isintance() functions.
August 12th, 2004, 07:31 AM
I have the same problem. I also have mxDateTime installed. It's a bit tricky to debug. The error occurs in the _mysql-code so nothing is really returned back other than a traceback. I run MySQL 4.1.3. I've heard rumors about a change in some of the date-types in mysql > 4. The trouble lies within timestamp for me too. I'll dig deeper into the problem. Please notify me if you find a soulution.
August 12th, 2004, 08:25 AM
I've found a workaround that works for me (only works if you use mxDateTime). I've written a new converter instead of of 'mysql_timestamp_converter'. Funny thing, but sending the converter via the conv-argument in the connection string doesn't work so I have to set it after I've connected.
import MySQLdb as dbi
from mx.DateTime import DateTimeFrom
"""Convert MYSQL TIMESTAMP"""
conn = dbi.connect(db='testdb', user='testuser'.....)
conn.converter = timestampConverter
That's about it. Like I said. Works for me.