#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    2
    Rep Power
    0

    ValueError with times in MySQLdb


    Hello,

    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?

    Thanks,

    daw
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    2
    Rep Power
    0
    Still same conditions, but I've narrowed it down to a MySQL timestamp field.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.

    Take care,

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    2
    Rep Power
    0
    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.

    Regards,
    /Marcus Pettersson
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    2
    Rep Power
    0
    Hi (again)

    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.

    Example :
    import MySQLdb as dbi
    from mx.DateTime import DateTimeFrom

    def timestampConverter(s):
    """Convert MYSQL TIMESTAMP"""
    return DateTimeFrom(s)

    conn = dbi.connect(db='testdb', user='testuser'.....)
    conn.converter[7] = timestampConverter

    ...
    ...

    That's about it. Like I said. Works for me.

    Regards,
    /Marcus Pettersson

IMN logo majestic logo threadwatch logo seochat tools logo