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: 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 To: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Hello everyone=2C greetings from Hong Kong.=0A= =0A= I'm a relative noob with Python and have managed to break it. I'm hoping so= meone would be kind enough to help out=2C or perhaps just point me in the r= ight direction.=0A= =0A= I've written a program which pulls in an XML document from an API on a serv= er and populates the data into a MySQL table which I will then use to creat= e reports. Everything is fine up until the point it tries to write the reco= rd to MySQL with this statement:=0A= =0A= dbcur.execute("INSERT INTO BackupJobs (bj_bsname=2C bj_bsid=2C bj_startdate= =2C bj_starttime=2C bj_enddate=2C bj_endtime=2C bj_status=2C bj_uploadsize)= values (%s=2C%s=2C%s=2C%s=2C%s=2C%s=2C%s=2C%s)"=2C newrecord)=0A= =0A= which borks with this:=0A= =0A= Traceback (most recent call last):=0A= =A0 File "./blahblahblah.py"=2C line 99=2C in =0A= =A0=A0=A0 dbcur.execute("INSERT INTO BackupJobs (bj_bsname=2C bj_bsid=2C bj= _startdate=2C bj_starttime=2C bj_enddate=2C bj_endtime=2C bj_status=2C bj_u= ploadsize) values (%s=2C%s=2C%s=2C%s=2C%s=2C%s=2C%s=2C%s)"=2C newrecord)=0A= =A0 File "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py"=2C lin= e 100=2C in execute=0A= =A0=A0=A0 escaped_args =3D tuple(conn.escape(arg) for arg in args)=0A= =A0 File "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py"=2C lin= e 100=2C in =0A= =A0=A0=A0 escaped_args =3D tuple(conn.escape(arg) for arg in args)=0A= =A0 File "/usr/local/lib/python3.2/dist-packages/pymysql/connections.py"=2C= line 650=2C in escape=0A= =A0=A0=A0 return escape_item(obj=2C self.charset)=0A= =A0 File "/usr/local/lib/python3.2/dist-packages/pymysql/converters.py"=2C = line 31=2C in escape_item=0A= =A0=A0=A0 encoder =3D encoders[type(val)]=0A= KeyError: =0A= =0A= I can dump out the (dummy) contents of the table using:=0A= =0A= for r in dbcur:=0A= =A0=A0=A0 print(r)=0A= =0A= ...so it seems the connection itself is working. User ID has full permissio= ns=2C I'm pretty sure the data types are correct for each field.=0A= =0A= I can provide more code snippets if necessary.=0A= =0A= I'd be very grateful for any help. And if you're in Hong Kong and have help= ed me through this I'll buy you a beer too :-) =