ValueError: invalid literal for int() with base 10: ''

566 views
Skip to first unread message

Nik

unread,
May 26, 2009, 10:19:10 AM5/26/09
to web2py Web Framework
Traceback (most recent call last):
File "/home/ern/web2py/gluon/restricted.py", line 107, in restricted
exec ccode in environment
File "/home/ern/web2py/applications/smb/views/appadmin.html", line
122, in <module>
File "/home/ern/web2py/gluon/sqlhtml.py", line 623, in __init__
for (rc, record) in enumerate(sqlrows):
File "/home/ern/web2py/gluon/sql.py", line 2196, in __iter__
yield self[i]
File "/home/ern/web2py/gluon/sql.py", line 2151, in __getitem__
str(value)[:10].strip().split('-')]
ValueError: invalid literal for int() with base 10: ''

I was trying to go to database administration of db2 when I got this
error. The table is defined as follows:

db2.define_table('msg_log',
SQLField('type', 'string'),
SQLField('smsc', 'string'),
SQLField('sent', 'datetime'),
SQLField('received', 'datetime'),
SQLField('sender', 'string'),
SQLField('receiver', 'string'),
SQLField('msgid', 'string'), migrate=False)

mdipierro

unread,
May 26, 2009, 10:36:44 AM5/26/09
to web2py Web Framework
There is corrupted data in the db. This can happen if you changed the
type of a 'date/datetime' field in sqlite. It can be reparied but I
need to know what you did. It may be easier to dump the db to csv,
erase it and reload it.

Massimo

NikG

unread,
May 26, 2009, 10:49:07 AM5/26/09
to web2py Web Framework
I'm pretty sure they're not corrupted since I can still access the
database just fine. The database, by the way, is updated by another
process not by my w2p application.

I tried to reload the data as you suggested but I still get the same
error.

mdipierro

unread,
May 26, 2009, 12:26:32 PM5/26/09
to web2py Web Framework
That is what I mean by corrupted. The datetime is not stored in the
proper ISO format by the other process.

Massimo

NikG

unread,
May 26, 2009, 2:29:27 PM5/26/09
to web2py Web Framework
Ahh. You are absolutely right.

Looking at the source code of the other process, it was creating
datetime in the following format: "%Y-%m-%d %H:%M:%S"

Thank you.

NikG

unread,
May 27, 2009, 2:15:36 AM5/27/09
to web2py Web Framework
I found the source of my problem. I have records with null values. And
since sqlite don't enforce data typing, I assume that it simply
"guess" the data type, based on whatever is found in the first(???)
record.

On this assumption, I assigned datetime values in the empty datetime
fields and tested again. It's now working.

Keith Planer

unread,
Dec 30, 2013, 2:40:03 PM12/30/13
to web...@googlegroups.com
I'm having the same problem, but I'm struggling with saving the database. The corrupted field is a 'date' type.

Oasis Agano

unread,
May 3, 2018, 3:22:22 PM5/3/18
to web2py-users
You can try and use this:

def is_date(string):
try:
parse(string)
return True
except ValueError:
return False


if is_date(str(row['Created'])):
request_created_date = datetime.datetime.strftime(row['Created'], "%Y-%m-%d %H:%M:%S")
else:
request_created_date = datetime.datetime.now()


It worked for me.

Good luck
Reply all
Reply to author
Forward
0 new messages