Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'error:': 0.07; 'extent': 0.07; 'initialize': 0.07; 'args)': 0.09; 'cookie': 0.09; 'encoder': 0.09; 'escape': 0.09; 'exist,': 0.09; 'here?': 0.09; 'host,': 0.09; 'cc:addr:python-list': 0.11; 'wrote': 0.14; 'random': 0.14; '"key': 0.16; '%s,': 0.16; "'/'": 0.16; 'arg': 0.16; 'skip:" 70': 0.16; 'subject:fails': 0.16; 'subject:when': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'cc:addr:python.org': 0.22; '31,': 0.24; 'integer': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'skip:" 40': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'record': 0.27; 'am,': 0.29; '???': 0.30; 'nature': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'gives': 0.31; 'code': 0.31; 'keyerror:': 0.31; 'file': 0.32; 'url:python': 0.33; 'problem': 0.35; 'knowledge': 0.35; 'received:google.com': 0.35; 'module.': 0.36; 'url:listinfo': 0.36; "i'll": 0.36; 'url:org': 0.36; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'does': 0.39; 'though,': 0.39; 'url:mail': 0.40; 'new': 0.61; 'browser': 0.61; 'first': 0.61; 'to:addr:gmail.com': 0.65; 'subject:get': 0.81; '650,': 0.84; 'treating': 0.84; 'visitor': 0.84; 'skip:& 80': 0.91; 'skip:\xc1 10': 0.91; 'vip': 0.96; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=ZhkXaT7n9zdx2baYGU33JXHb8y5K1K9zXt/ZOG5jrdE=; b=xXSgb4eHKJTn+psjJx2EaSKlrdPFvbKjP2m8H6UjvDVq5xyNKlLH1bhaJ4E4lWnKmG rW/a9RELDn6UT+X/SvroGR7D32vyFG0DY2VHNNRmG4d7gTUtB43/i5lzA21LJGZ280x8 5zLYa/BSNkHG8Gdq8p0it+jL8HyXC+i0w480XhGKk9Hau8kqPYVGHdTSRcLo068T5jap vVVahOlSpAL+BwxKrdTKbqdZCmkJqbXXPJiVXUGlF6zgHPwGboC5tbN+F6S7C3ON6g2s 1uVk3A6Y6jDExoDzvVKpNKXzs1fylCJ9k1uNq+UDSthP1jkCbhY/3mQVevrO1MXR65V3 iAyw== MIME-Version: 1.0 X-Received: by 10.49.88.3 with SMTP id bc3mr24608003qeb.30.1380983758156; Sat, 05 Oct 2013 07:35:58 -0700 (PDT) Sender: manicpolymath@gmail.com In-Reply-To: References: Date: Sat, 5 Oct 2013 09:35:58 -0500 X-Google-Sender-Auth: _jZo1hiktoiZi3YKcqB0izBMpnY Subject: Re: Select fails when cookie tried to get a numeric value From: Benjamin Rovny To: =?ISO-8859-7?B?zd/q7/Igwevl7vzw7/Xr7/I=?= Content-Type: multipart/alternative; boundary=047d7bd6aeba587a4404e7ff5604 X-Mailman-Approved-At: Sat, 05 Oct 2013 22:39:54 +0200 Cc: python-list@python.org 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: 148 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381005595 news.xs4all.nl 15967 [2001:888:2000:d::a6]:52287 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56219 --047d7bd6aeba587a4404e7ff5604 Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable On Oct 5, 2013 8:42 AM, "=CD=DF=EA=EF=F2 =C1=EB=E5=EE=FC=F0=EF=F5=EB=EF=F2"= wrote: > > # initialize cookie > cookie =3D cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') ) > cookie.load( cookie ) > vip =3D cookie.get('ID') > > ....... > ....... > > # if browser cookie does not exist, set it > vip =3D random.randrange(0, 10000) > cookie['ID'] =3D vip > cookie['ID']['path'] =3D '/' Problem here? Randrange returns an integer here, which you are then treating like a dictionary (hence "Key Error"). That's the extent of my knowledge though, I don't know about the "cookie" module. > > # first time visitor on this page, create new record > cur.execute('''INSERT INTO visitors (counterID, cookieID, host, city, useros, browser, ref, lastvisit) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''', (cID, vip, host, city, useros, browser, ref, lastvisit) ) > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > The above code i wrote gives me the following error: > > > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] File "/home/nikos/public_html/cgi-bin/metrites.py", line 209, in > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] cur.execute('''SELECT * FROM visitors WHERE counterID =3D %s and cookieID = =3D %s''', (cID, vip) ) > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 100, in execute > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] escaped_args =3D tuple(conn.escape(arg) for arg in args) > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 100, in > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] escaped_args =3D tuple(conn.escape(arg) for arg in args) > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/connections.py", line 650, in escape > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] return escape_item(obj, self.charset) > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/converters.py", line 31, in escape_item > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] encoder = =3D encoders[type(val)] > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] KeyError: > > What is the nature of the error? > ??? > > I'll iam trying to do is to give a cookie a random number. > -- > https://mail.python.org/mailman/listinfo/python-list --047d7bd6aeba587a4404e7ff5604 Content-Type: text/html; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable


On Oct 5, 2013 8:42 AM, "=CD=DF=EA=EF=F2 =C1=EB=E5=EE=FC=F0=EF=F5=EB= =EF=F2" <nikos.gr33k@gmail= .com> wrote:
>
> # initialize cookie
> cookie =3D cookies.SimpleCookie( os.environ.get('HTTP_COOKIE')= )
> cookie.load( cookie )
> vip =3D cookie.get('ID')
>
> .......
> .......
>
> # if browser cookie does not exist, set it
> vip =3D random.randrange(0, 10000)
> cookie['ID'] =3D vip
> cookie['ID']['path'] =3D '/'

Problem here? Randrange returns an integer here, which you a= re then treating like a dictionary (hence "Key Error"). That'= s the extent of my knowledge though, I don't know about the "cooki= e" module.

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> # first time visitor on this page, create new record
> cur.execute('''INSERT INTO visitors (counterID, cookieID, = host, city, useros, browser, ref, lastvisit) VALUES (%s, %s, %s, %s, %s, %s= , %s, %s)''', (cID, vip, host, city, useros, browser, ref, last= visit) )
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> The above code i wrote gives me the following error:
>
>
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 File &= quot;/home/nikos/public_html/cgi-bin/metrites.py", line 209, in <mo= dule>
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] cur.execut= e('''SELECT * FROM visitors WHERE counterID =3D %s and cookieID= =3D %s''', (cID, vip) )
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 File &= quot;/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py&q= uot;, line 100, in execute
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] escaped_ar= gs =3D tuple(conn.escape(arg) for arg in args)
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 File &= quot;/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py&q= uot;, line 100, in <genexpr>
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] escaped_ar= gs =3D tuple(conn.escape(arg) for arg in args)
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 File &= quot;/usr/local/bin/python/lib/python3.3/site-packages/pymysql/connections.= py", line 650, in escape
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 =A0 re= turn escape_item(obj, self.charset)
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 File &= quot;/usr/local/bin/python/lib/python3.3/site-packages/pymysql/converters.p= y", line 31, in escape_item
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] =A0 =A0 en= coder =3D encoders[type(val)]
> [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] KeyError: = <class 'http.cookies.Morsel'>
>
> What is the nature of the error?
> <class 'http.cookies.Morsel'> =A0???
>
> I'll iam trying to do is to give a cookie a random number.
> --
> https= ://mail.python.org/mailman/listinfo/python-list

--047d7bd6aeba587a4404e7ff5604--