pymysql KeyError

C

Chris Green

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top