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


Groups > comp.lang.python > #43268

pymysql KeyError

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chrisgreen@hotmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'beer': 0.05; 'skip:" 60': 0.07; 'tries': 0.07; 'args)': 0.09; 'encoder': 0.09; 'escape': 0.09; 'reports.': 0.09; 'api': 0.11; 'python': 0.11; 'arg': 0.16; 'dump': 0.16; 'permissions,': 0.16; ':-)': 0.16; 'everyone,': 0.19; 'working.': 0.19; 'written': 0.21; 'help.': 0.21; 'seems': 0.21; 'to:name:python-list@python.org': 0.22; '31,': 0.24; 'necessary.': 0.24; 'fine': 0.24; "i've": 0.25; 'this:': 0.26; 'skip:" 20': 0.27; 'values': 0.27; 'record': 0.27; 'point': 0.28; 'correct': 0.29; 'xml': 0.29; 'relative': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'code': 0.31; 'keyerror:': 0.31; 'file': 0.32; '(most': 0.33; 'table': 0.34; 'skip:d 20': 0.34; "i'd": 0.34; 'connection': 0.35; 'grateful': 0.36; "i'll": 0.36; 'too': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'itself': 0.39; '\xa0\xa0\xa0': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'break': 0.61; 'field.': 0.61; 'full': 0.61; "you're": 0.61; 'kind': 0.63; 'provide': 0.64; 'more': 0.64; 'greetings': 0.72; 'hoping': 0.75; '650,': 0.84; 'hong': 0.91; 'kong': 0.91
X-EIP [AaU9cIbeS2ErSV5faehEwaAu5E0Dfipr]
X-Originating-Email [chrisgreen@hotmail.com]
From Chris Green <chrisgreen@hotmail.com>
To "python-list@python.org" <python-list@python.org>
Subject pymysql KeyError
Date Wed, 10 Apr 2013 18:53:29 +0800
Importance Normal
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-OriginalArrivalTime 10 Apr 2013 10:53:31.0069 (UTC) FILETIME=[A3AF8ED0:01CE35D9]
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.407.1365591278.3114.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365591278 news.xs4all.nl 2709 [2001:888:2000:d::a6]:54325
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43268

Show key headers only | 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