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


Groups > comp.lang.python > #43268 > unrolled thread

pymysql KeyError

Started byChris Green <chrisgreen@hotmail.com>
First post2013-04-10 18:53 +0800
Last post2013-04-10 18:53 +0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#43268 — pymysql KeyError

FromChris Green <chrisgreen@hotmail.com>
Date2013-04-10 18:53 +0800
Subjectpymysql KeyError
Message-ID<mailman.407.1365591278.3114.python-list@python.org>
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 :-) 		 	   		  

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web