Select fails when cookie tried to get a numeric value
Νίκος Αλεξόπουλος
nikos.gr33k at gmail.com
Sat Oct 5 10:24:17 EDT 2013
Στις 5/10/2013 4:59 μμ, ο/η Chris Angelico έγραψε:
> On Sat, Oct 5, 2013 at 11:38 PM, Νίκος Αλεξόπουλος
> <nikos.gr33k at gmail.com> wrote:
>> 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) )
>
> No, I don't think it does give you that error! Nikos, you've been
> around this group a good while; why can you not learn to read an
> exception traceback? Find line 209, which (as Ned said) is the one to
> focus on, and look at it. If you can't figure it out yourself, at the
> VERY least do us all a courtesy and show us the actual code that's
> having the problem!
But i have given you the line that produces the error:
# initialize cookie
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
cookieID = cookie.get('ID')
# if browser cookie does not exist, set it
if not cookieID:
message = "ΑΠΟ ΔΩ ΚΑΙ ΣΤΟ ΕΞΗΣ ΔΕΝ ΣΕ ΕΙΔΑ, ΔΕΝ ΣΕ ΞΕΡΩ, ΔΕΝ ΣΕ
ΑΚΟΥΣΑ! ΘΑ ΕΙΣΑΙ ΠΛΕΟΝ Ο ΑΟΡΑΤΟΣ ΕΠΙΣΚΕΠΤΗΣ!!"
cookie['ID'] = random.randrange(0, 10000)
cookie['ID']['path'] = '/'
cookie['ID']['expires'] = 60*60*24*365 #this cookie will expire in a month
For some reason i think CookieID nevers gets inserted itnot the database
that's why mysql's select statemnt fails.
When i print CookieID i was under the impression i would see a random
number like '5369' but instead it display the follwong.
Set-Cookie: ID="Set-Cookie: ID=5369"
The mysql filed CookieID is of datatype's int(5) so it cannto store this
value.
If iam correct and thi is trully the problem then how can i just get the
random number part out the whole string?
--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>
More information about the Python-list
mailing list