|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Still same conditions, but I've narrowed it down to a MySQL timestamp field.
|
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > ValueError with times in MySQLdb |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|