Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43268

pymysql KeyError

From Chris Green <chrisgreen@hotmail.com>
Subject pymysql KeyError
Date 2013-04-10 18:53 +0800
Newsgroups comp.lang.python
Message-ID <mailman.407.1365591278.3114.python-list@python.org> (permalink)

Show all headers | View raw


Hello everyone, greetings from Hong Kong.

I'm a relative noob with Python and have managed to break it. I'm hoping someone would be kind enough to help out, or perhaps just point me in the right direction.

I've written a program which pulls in an XML document from an API on a server and populates the data into a MySQL table which I will then use to create reports. Everything is fine up until the point it tries to write the record to MySQL with this statement:

dbcur.execute("INSERT INTO BackupJobs (bj_bsname, bj_bsid, bj_startdate, bj_starttime, bj_enddate, bj_endtime, bj_status, bj_uploadsize) values (%s,%s,%s,%s,%s,%s,%s,%s)", newrecord)

which borks with this:

Traceback (most recent call last):
  File "./blahblahblah.py", line 99, in <module>
    dbcur.execute("INSERT INTO BackupJobs (bj_bsname, bj_bsid, bj_startdate, bj_starttime, bj_enddate, bj_endtime, bj_status, bj_uploadsize) values (%s,%s,%s,%s,%s,%s,%s,%s)", newrecord)
  File "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py", line 100, in execute
    escaped_args = tuple(conn.escape(arg) for arg in args)
  File "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py", line 100, in <genexpr>
    escaped_args = tuple(conn.escape(arg) for arg in args)
  File "/usr/local/lib/python3.2/dist-packages/pymysql/connections.py", line 650, in escape
    return escape_item(obj, self.charset)
  File "/usr/local/lib/python3.2/dist-packages/pymysql/converters.py", line 31, in escape_item
    encoder = encoders[type(val)]
KeyError: <class 'builtin_function_or_method'>

I can dump out the (dummy) contents of the table using:

for r in dbcur:
    print(r)

...so it seems the connection itself is working. User ID has full permissions, I'm pretty sure the data types are correct for each field.

I can provide more code snippets if necessary.

I'd be very grateful for any help. And if you're in Hong Kong and have helped me through this I'll buy you a beer too :-) 		 	   		  

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

pymysql KeyError Chris Green <chrisgreen@hotmail.com> - 2013-04-10 18:53 +0800

csiph-web