Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 28th, 2004, 03:22 PM
daw daw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 daw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old July 28th, 2004, 04:57 PM
daw daw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 daw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Still same conditions, but I've narrowed it down to a MySQL timestamp field.

Reply With Quote
  #3  
Old July 29th, 2004, 03:02 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 2 m 16 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #4  
Old August 12th, 2004, 06:31 AM
garcus garcus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 garcus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #5  
Old August 12th, 2004, 07:25 AM
garcus garcus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 garcus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > ValueError with times in MySQLdb


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway