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


Groups > comp.lang.python > #43271

Re: pymysql KeyError

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'beer': 0.05; 'skip:" 60': 0.07; 'tries': 0.07; 'args)': 0.09; 'encoder': 0.09; 'escape': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'reports.': 0.09; 'shows.': 0.09; 'api': 0.11; 'python': 0.11; 'arg': 0.16; 'dump': 0.16; 'guessing': 0.16; 'permissions,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'everyone,': 0.19; 'working.': 0.19; 'written': 0.21; 'help.': 0.21; 'seems': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; '31,': 0.24; 'necessary.': 0.24; 'fine': 0.24; "i've": 0.25; 'this:': 0.26; 'skip:" 20': 0.27; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'record': 0.27; 'point': 0.28; 'correct': 0.29; 'chris': 0.29; 'xml': 0.29; 'forgot': 0.30; '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; 'add': 0.35; 'grateful': 0.36; 'method': 0.36; "i'll": 0.36; 'too': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'itself': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'tell': 0.60; '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-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: pymysql KeyError
Date Wed, 10 Apr 2013 13:20:53 +0200
Organization None
References <COL126-W38307A22A5E3C9A96627CFD7C70@phx.gbl>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084b041.dip.t-dialin.net
User-Agent KNode/4.7.3
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.410.1365592810.3114.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365592810 news.xs4all.nl 2643 [2001:888:2000:d::a6]:42910
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43271

Show key headers only | View raw


Chris Green wrote:

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

Add a

print(newrecord)

before the 

dbcur.execute(...)

line and tell us what it shows. I'm guessing that for one of the values in 
it you forgot to call a method written in C, e. g.

>>> [42].pop
<built-in method pop of list object at 0x7f86f70bc950>
>>> type(_)
<class 'builtin_function_or_method'>

instead of

>>> [42].pop()
42

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


Thread

Re: pymysql KeyError Peter Otten <__peter__@web.de> - 2013-04-10 13:20 +0200

csiph-web