On Oct 5, 2013 8:42 AM, "Νίκος Αλεξόπουλος" <nikos.gr...@gmail.com> wrote: > > # initialize cookie > cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') ) > cookie.load( cookie ) > vip = cookie.get('ID') > > ....... > ....... > > # if browser cookie does not exist, set it > vip = random.randrange(0, 10000) > cookie['ID'] = vip > cookie['ID']['path'] = '/'
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) ) > ======================================= > 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 <module> > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] cur.execute('''SELECT * FROM visitors WHERE counterID = %s and cookieID = %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 = 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 <genexpr> > [Sat Oct 05 13:33:24 2013] [error] [client 108.162.229.114] escaped_args = 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 = 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'> ??? > > I'll iam trying to do is to give a cookie a random number. > -- > https://mail.python.org/mailman/listinfo/python-list
-- https://mail.python.org/mailman/listinfo/python-list