Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56183 > unrolled thread
| Started by | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| First post | 2013-10-05 16:38 +0300 |
| Last post | 2013-10-06 22:16 -0400 |
| Articles | 20 on this page of 33 — 10 participants |
Back to article view | Back to comp.lang.python
Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 16:38 +0300
Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 09:53 -0400
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:40 +0300
Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 10:54 -0400
Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 11:12 -0400
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 18:31 +0300
Re: Select fails when cookie tried to get a numeric value Andreas Perstinger <andipersti@gmail.com> - 2013-10-05 17:47 +0200
Re: Select fails when cookie tried to get a numeric value Chris Angelico <rosuav@gmail.com> - 2013-10-06 09:36 +1100
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 18:52 +0300
Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 12:08 -0400
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 19:14 +0300
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 19:17 +0300
Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 12:42 -0400
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 19:53 +0300
Re: Select fails when cookie tried to get a numeric value Zero Piraeus <z@etiol.net> - 2013-10-05 12:06 -0300
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 18:50 +0300
Re: Select fails when cookie tried to get a numeric value Chris Angelico <rosuav@gmail.com> - 2013-10-05 23:59 +1000
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:24 +0300
Re: Select fails when cookie tried to get a numeric value Chris Angelico <rosuav@gmail.com> - 2013-10-06 00:28 +1000
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:30 +0300
Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 10:43 -0400
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:47 +0300
Re: Select fails when cookie tried to get a numeric value Zero Piraeus <z@etiol.net> - 2013-10-05 11:44 -0300
Re: Select fails when cookie tried to get a numeric value MRAB <python@mrabarnett.plus.com> - 2013-10-05 17:51 +0100
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:28 +0300
Re: Select fails when cookie tried to get a numeric value Andreas Perstinger <andipersti@gmail.com> - 2013-10-05 18:56 +0200
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 20:38 +0300
Re: Select fails when cookie tried to get a numeric value Benjamin Rovny <rdr.vladimir@gmail.com> - 2013-10-05 09:35 -0500
Re: Select fails when cookie tried to get a numeric value Terry Reedy <tjreedy@udel.edu> - 2013-10-05 18:06 -0400
Re: Select fails when cookie tried to get a numeric value Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-05 23:36 +0000
Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-06 08:20 +0300
Re: Select fails when cookie tried to get a numeric value Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-06 14:57 +0000
Re: Select fails when cookie tried to get a numeric value Piet van Oostrum <piet@vanoostrum.org> - 2013-10-06 22:16 -0400
Page 1 of 2 [1] 2 Next page →
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 16:38 +0300 |
| Subject | Select fails when cookie tried to get a numeric value |
| Message-ID | <l2p4o4$4ht$1@dont-email.me> |
# 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'] = '/'
# 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.
[toc] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-10-05 09:53 -0400 |
| Message-ID | <mailman.743.1380981201.18130.python-list@python.org> |
| In reply to | #56183 |
On 10/5/13 9:38 AM, Νίκος Αλεξόπουλος 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'] = '/'
>
> # 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.
An important skill to master is reading the traceback for clues. It
shows you the lines of code that are involved in the failure. If you
read up the stack from the bottom, you can see that bottom four stack
frames are in the pymysql package. But the fifth frame is in your code,
at metrites.py, like 209, executing a select SQL statement. That's the
line to focus on.
You haven't shown us that code, but that is where the problem is.
From reading the bottom-most frame, you can see that the problem is
that "val" is an http.cookies.Morsel object. This means you probably
tried to use a cookie object as data in your SQL query, and MySQL
doesn't know what to do with that object. You'll have to use a more
primitive piece of data in your query.
--Ned.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 17:40 +0300 |
| Message-ID | <l2p8cl$j06$4@dont-email.me> |
| In reply to | #56184 |
Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
> From reading the bottom-most frame, you can see that the problem is
> that "val" is an http.cookies.Morsel object. This means you probably
> tried to use a cookie object as data in your SQL query, and MySQL
> doesn't know what to do with that object. You'll have to use a more
> primitive piece of data in your query.
# 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:
cookie['ID'] = random.randrange(0, 10000)
cookie['ID']['path'] = '/'
cookie['ID']['expires'] = 60*60*24*365 #this cookie will expire in a month
cookieID = cookie.get('ID')
print( cookie )
In the above code i try to retrive the cookie form the visitor's browser
and if it does nto exist i create one.
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?
Do you see something wrong?
Why cookie['ID'] retuned this string back and not just the number?
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-10-05 10:54 -0400 |
| Message-ID | <mailman.747.1380984876.18130.python-list@python.org> |
| In reply to | #56190 |
On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>
>> From reading the bottom-most frame, you can see that the problem is
>> that "val" is an http.cookies.Morsel object. This means you probably
>> tried to use a cookie object as data in your SQL query, and MySQL
>> doesn't know what to do with that object. You'll have to use a more
>> primitive piece of data in your query.
>
> # 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:
> cookie['ID'] = random.randrange(0, 10000)
> cookie['ID']['path'] = '/'
> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
> expire in a month
> cookieID = cookie.get('ID')
> print( cookie )
>
>
> In the above code i try to retrive the cookie form the visitor's
> browser and if it does nto exist i create one.
>
>
>
> 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?
>
> Do you see something wrong?
> Why cookie['ID'] retuned this string back and not just the number?
>
>
Nikos: stop sending so many emails. You've asked this question 3 times
now in this thread. You aren't even giving people a chance to respond.
If you want immediate feedback, use IRC. Email takes a little longer.
--Ned.
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-10-05 11:12 -0400 |
| Message-ID | <mailman.748.1380985965.18130.python-list@python.org> |
| In reply to | #56190 |
On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>
>> From reading the bottom-most frame, you can see that the problem is
>> that "val" is an http.cookies.Morsel object. This means you probably
>> tried to use a cookie object as data in your SQL query, and MySQL
>> doesn't know what to do with that object. You'll have to use a more
>> primitive piece of data in your query.
>
> # 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:
> cookie['ID'] = random.randrange(0, 10000)
> cookie['ID']['path'] = '/'
> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
> expire in a month
> cookieID = cookie.get('ID')
> print( cookie )
>
>
> In the above code i try to retrive the cookie form the visitor's
> browser and if it does nto exist i create one.
>
>
>
> 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?
>
> Do you see something wrong?
> Why cookie['ID'] retuned this string back and not just the number?
>
>
Thanks for being patient. Where you have this:
cookieID = cookie.get('ID')
you actually want this:
cookieID = cookie.get('ID').value
--Ned.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 18:31 +0300 |
| Message-ID | <l2pbcs$88r$1@dont-email.me> |
| In reply to | #56194 |
Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>
>>> From reading the bottom-most frame, you can see that the problem is
>>> that "val" is an http.cookies.Morsel object. This means you probably
>>> tried to use a cookie object as data in your SQL query, and MySQL
>>> doesn't know what to do with that object. You'll have to use a more
>>> primitive piece of data in your query.
>>
>> # 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:
>> cookie['ID'] = random.randrange(0, 10000)
>> cookie['ID']['path'] = '/'
>> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
>> expire in a month
>> cookieID = cookie.get('ID')
>> print( cookie )
>>
>>
>> In the above code i try to retrive the cookie form the visitor's
>> browser and if it does nto exist i create one.
>>
>>
>>
>> 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?
>>
>> Do you see something wrong?
>> Why cookie['ID'] retuned this string back and not just the number?
>>
>>
>
> Thanks for being patient. Where you have this:
>
> cookieID = cookie.get('ID')
>
> you actually want this:
>
> cookieID = cookie.get('ID').value
>
> --Ned.
Thank you Ned, indeed '.value' needed to just print the number.
Now i have it like this:
# connect to database
con = pymysql.connect( db = 'nikos_metrites', user = 'nikos_root',
passwd = 't1abhp2r!', charset = 'utf8', host = 'localhost' )
cur = con.cursor()
# initialize cookie and retrieve cookie from clients broswer
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
# if browser cookie does not exist, set it
if not cookie.get('ID'):
cookie['ID'] = random.randrange(0, 10000)
cookie['ID']['path'] = '/'
cookie['ID']['expires'] = 60*60*24*365 #this cookie will expire in a month
print( cookie )
cookieID = cookie['ID'].value
# if browser cookie exist, just retrieve it
else:
cookieID = cookie.get('ID').value
and it does not output an error, but for some reason the inserting and
selecting never happens.
here si the releveant code:
if cookieID != 1977 and re.search(
r'(msn|gator|amazon|yandex|reverse|who|cloudflare|fetch|barracuda|spider|google|crawl|pingdom)',
host ) is None:
try:
# find the visitor record for the (saved) cID and current host
cur.execute('''SELECT * FROM visitors WHERE counterID = %s and
cookieID = %s''', (cID, cookieID) )
data = cur.fetchone() #cookieID is unique
if not data:
# 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, cookieID, host, city, useros, browser, ref, lastvisit) )
else:
# found the page, save its primary key for later use
vID = data[0]
# UPDATE record using retrieved vID
cur.execute('''UPDATE visitors SET host = %s, city = %s, useros = %s,
browser = %s, ref= %s, hits = hits + 1, lastvisit = %s
WHERE counterID = %s and cookieID = %s''', (host, city, useros,
browser, ref, lastvisit, vID, cookieID) )
except pymysql.ProgrammingError as e:
print( repr(e) )
sys.exit(0)
=====================
Any ideas as to what i shoudld try?
the statemnt don't return any error back though and the cookieID is
indeed now a proper number so i see no reason as to why they fail.
--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>
[toc] | [prev] | [next] | [standalone]
| From | Andreas Perstinger <andipersti@gmail.com> |
|---|---|
| Date | 2013-10-05 17:47 +0200 |
| Message-ID | <mailman.750.1380988091.18130.python-list@python.org> |
| In reply to | #56197 |
On 05.10.2013 17:31, Νίκος Αλεξόπουλος wrote: > Now i have it like this: > > # connect to database > con = pymysql.connect( db = 'nikos_metrites', user = 'nikos_root', > passwd = 't1abhp2r!', charset = 'utf8', host = 'localhost' ) Just to be sure: That's not your real password, is it? Bye, Andreas
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-10-06 09:36 +1100 |
| Message-ID | <mailman.763.1381012585.18130.python-list@python.org> |
| In reply to | #56197 |
On Sun, Oct 6, 2013 at 1:31 AM, Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> wrote:
> # find the visitor record for the (saved) cID and current
> host
> cur.execute('''SELECT * FROM visitors WHERE counterID = %s
> and cookieID = %s''', (cID, cookieID) )
>
> data = cur.fetchone() #cookieID is unique
>
> if not data:
>
> # 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, cookieID, host, city, useros, browser, ref,
> lastvisit) )
> else:
> # found the page, save its primary key for later use
> vID = data[0]
> # UPDATE record using retrieved vID
> cur.execute('''UPDATE visitors SET host = %s, city =
> %s, useros = %s, browser = %s, ref= %s, hits = hits + 1, lastvisit = %s
>
> WHERE counterID = %s and cookieID = %s''', (host, city, useros, browser,
> ref, lastvisit, vID, cookieID) )
Do you understand the expression "race condition", and how it applies
to the above code? If not, you MUST read up on that before relying on
code like this, and as that's not a Python question, I recommend
Google and Wikipedia.[1]
ChrisA
[1] Yes, I know they're not primary sources. For something like this,
tertiary sources are going to do him fine.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 18:52 +0300 |
| Message-ID | <l2pckd$f30$2@dont-email.me> |
| In reply to | #56194 |
Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>
>>> From reading the bottom-most frame, you can see that the problem is
>>> that "val" is an http.cookies.Morsel object. This means you probably
>>> tried to use a cookie object as data in your SQL query, and MySQL
>>> doesn't know what to do with that object. You'll have to use a more
>>> primitive piece of data in your query.
>>
>> # 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:
>> cookie['ID'] = random.randrange(0, 10000)
>> cookie['ID']['path'] = '/'
>> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
>> expire in a month
>> cookieID = cookie.get('ID')
>> print( cookie )
>>
>>
>> In the above code i try to retrive the cookie form the visitor's
>> browser and if it does nto exist i create one.
>>
>>
>>
>> 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?
>>
>> Do you see something wrong?
>> Why cookie['ID'] retuned this string back and not just the number?
>>
>>
>
> Thanks for being patient. Where you have this:
>
> cookieID = cookie.get('ID')
>
> you actually want this:
>
> cookieID = cookie.get('ID').value
>
> --Ned.
[Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] File
"/home/nikos/public_html/cgi-bin/metrites.py", line 84, in <module>
[Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] cookieID
= cookie.get('ID').value
[Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]
AttributeError: 'NoneType' object has no attribute 'value'
--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-10-05 12:08 -0400 |
| Message-ID | <mailman.751.1380989312.18130.python-list@python.org> |
| In reply to | #56200 |
On 10/5/13 11:52 AM, Νίκος Αλεξόπουλος wrote:
> Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
>> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>>
>>>> From reading the bottom-most frame, you can see that the problem is
>>>> that "val" is an http.cookies.Morsel object. This means you probably
>>>> tried to use a cookie object as data in your SQL query, and MySQL
>>>> doesn't know what to do with that object. You'll have to use a more
>>>> primitive piece of data in your query.
>>>
>>> # 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:
>>> cookie['ID'] = random.randrange(0, 10000)
>>> cookie['ID']['path'] = '/'
>>> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
>>> expire in a month
>>> cookieID = cookie.get('ID')
>>> print( cookie )
>>>
>>>
>>> In the above code i try to retrive the cookie form the visitor's
>>> browser and if it does nto exist i create one.
>>>
>>>
>>>
>>> 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?
>>>
>>> Do you see something wrong?
>>> Why cookie['ID'] retuned this string back and not just the number?
>>>
>>>
>>
>> Thanks for being patient. Where you have this:
>>
>> cookieID = cookie.get('ID')
>>
>> you actually want this:
>>
>> cookieID = cookie.get('ID').value
>>
>> --Ned.
>
>
> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] File
> "/home/nikos/public_html/cgi-bin/metrites.py", line 84, in <module>
> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] cookieID =
> cookie.get('ID').value
> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]
> AttributeError: 'NoneType' object has no attribute 'value'
>
Nikos: you know enough to understand what is going on here.
This list will not serve you well if you take every error message and
paste it into an email without trying to get to the bottom of it
yourself. At the very least, a Google search on, "AttributeError:
'NoneType' object has no attribute 'value'" will find you some answers.
I've said it before, I'll say it again: slow down.
--Ned.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 19:14 +0300 |
| Message-ID | <l2pds7$ol2$1@dont-email.me> |
| In reply to | #56201 |
Στις 5/10/2013 7:08 μμ, ο/η Ned Batchelder έγραψε:
>
> On 10/5/13 11:52 AM, Νίκος Αλεξόπουλος wrote:
>> Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
>>> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>>>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>>>
>>>>> From reading the bottom-most frame, you can see that the problem is
>>>>> that "val" is an http.cookies.Morsel object. This means you probably
>>>>> tried to use a cookie object as data in your SQL query, and MySQL
>>>>> doesn't know what to do with that object. You'll have to use a more
>>>>> primitive piece of data in your query.
>>>>
>>>> # 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:
>>>> cookie['ID'] = random.randrange(0, 10000)
>>>> cookie['ID']['path'] = '/'
>>>> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
>>>> expire in a month
>>>> cookieID = cookie.get('ID')
>>>> print( cookie )
>>>>
>>>>
>>>> In the above code i try to retrive the cookie form the visitor's
>>>> browser and if it does nto exist i create one.
>>>>
>>>>
>>>>
>>>> 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?
>>>>
>>>> Do you see something wrong?
>>>> Why cookie['ID'] retuned this string back and not just the number?
>>>>
>>>>
>>>
>>> Thanks for being patient. Where you have this:
>>>
>>> cookieID = cookie.get('ID')
>>>
>>> you actually want this:
>>>
>>> cookieID = cookie.get('ID').value
>>>
>>> --Ned.
>>
>>
>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] File
>> "/home/nikos/public_html/cgi-bin/metrites.py", line 84, in <module>
>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] cookieID =
>> cookie.get('ID').value
>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]
>> AttributeError: 'NoneType' object has no attribute 'value'
>>
>
> Nikos: you know enough to understand what is going on here.
>
> This list will not serve you well if you take every error message and
> paste it into an email without trying to get to the bottom of it
> yourself. At the very least, a Google search on, "AttributeError:
> 'NoneType' object has no attribute 'value'" will find you some answers.
>
> I've said it before, I'll say it again: slow down.
>
> --Ned.
cookieID = cookie.get('ID').value
is not returning what you said it will return
and if cookie.get('ID') doenst exist it returns the error
AttributeError: 'NoneType' object has no attribute 'value'
These are 2 problem.
value aint being returned thw ehole Set-Cookie: ID=some_number is being
returned instead as tou cna see at http://superhost.gr/
and the second problem is
that if the cookie dosnt exist i get the error of: AttributeError:
'NoneType' object has no attribute 'value'
whne this line is tryign to be executed:
cookieID = cookie.get('ID').value
How can i deal with thse 2 problems?
--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 19:17 +0300 |
| Message-ID | <l2pe26$ol2$2@dont-email.me> |
| In reply to | #56202 |
Στις 5/10/2013 7:14 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:
> Στις 5/10/2013 7:08 μμ, ο/η Ned Batchelder έγραψε:
>>
>> On 10/5/13 11:52 AM, Νίκος Αλεξόπουλος wrote:
>>> Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
>>>> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>>>>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>>>>
>>>>>> From reading the bottom-most frame, you can see that the problem is
>>>>>> that "val" is an http.cookies.Morsel object. This means you probably
>>>>>> tried to use a cookie object as data in your SQL query, and MySQL
>>>>>> doesn't know what to do with that object. You'll have to use a more
>>>>>> primitive piece of data in your query.
>>>>>
>>>>> # 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:
>>>>> cookie['ID'] = random.randrange(0, 10000)
>>>>> cookie['ID']['path'] = '/'
>>>>> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
>>>>> expire in a month
>>>>> cookieID = cookie.get('ID')
>>>>> print( cookie )
>>>>>
>>>>>
>>>>> In the above code i try to retrive the cookie form the visitor's
>>>>> browser and if it does nto exist i create one.
>>>>>
>>>>>
>>>>>
>>>>> 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?
>>>>>
>>>>> Do you see something wrong?
>>>>> Why cookie['ID'] retuned this string back and not just the number?
>>>>>
>>>>>
>>>>
>>>> Thanks for being patient. Where you have this:
>>>>
>>>> cookieID = cookie.get('ID')
>>>>
>>>> you actually want this:
>>>>
>>>> cookieID = cookie.get('ID').value
>>>>
>>>> --Ned.
>>>
>>>
>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] File
>>> "/home/nikos/public_html/cgi-bin/metrites.py", line 84, in <module>
>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] cookieID =
>>> cookie.get('ID').value
>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]
>>> AttributeError: 'NoneType' object has no attribute 'value'
>>>
>>
>> Nikos: you know enough to understand what is going on here.
>>
>> This list will not serve you well if you take every error message and
>> paste it into an email without trying to get to the bottom of it
>> yourself. At the very least, a Google search on, "AttributeError:
>> 'NoneType' object has no attribute 'value'" will find you some answers.
>>
>> I've said it before, I'll say it again: slow down.
>>
>> --Ned.
>
>
> cookieID = cookie.get('ID').value
>
> is not returning what you said it will return
>
> and if cookie.get('ID') doenst exist it returns the error
> AttributeError: 'NoneType' object has no attribute 'value'
>
> These are 2 problem.
>
> value aint being returned thw ehole Set-Cookie: ID=some_number is being
> returned instead as tou cna see at http://superhost.gr/
>
> and the second problem is
>
> that if the cookie dosnt exist i get the error of: AttributeError:
> 'NoneType' object has no attribute 'value'
>
> whne this line is tryign to be executed:
> cookieID = cookie.get('ID').value
>
> How can i deal with thse 2 problems?
>
The best solution i cna think of is put the whole thing into a try: block
try:
cookieID = cookie.get('ID').value
except:
cookie['ID'] = random.randrange(0, 10000)
cookie['ID']['path'] = '/'
print( cookie )
cookieID = cookie['ID'].value
print( '''Content-type: text/html; charset=utf-8\n''' )
print( cookieID )
sys.exit(0)
That will avoid the NoneType errot but:
that still print out:
Set-Cookie: ID=7413
instead of just the number
--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-10-05 12:42 -0400 |
| Message-ID | <mailman.754.1380991748.18130.python-list@python.org> |
| In reply to | #56203 |
On 10/5/13 12:17 PM, Νίκος Αλεξόπουλος wrote:
> Στις 5/10/2013 7:14 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:
>> Στις 5/10/2013 7:08 μμ, ο/η Ned Batchelder έγραψε:
>>>
>>> On 10/5/13 11:52 AM, Νίκος Αλεξόπουλος wrote:
>>>> Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
>>>>> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>>>>>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>>>>>
>>>>>>> From reading the bottom-most frame, you can see that the
>>>>>>> problem is
>>>>>>> that "val" is an http.cookies.Morsel object. This means you
>>>>>>> probably
>>>>>>> tried to use a cookie object as data in your SQL query, and MySQL
>>>>>>> doesn't know what to do with that object. You'll have to use a
>>>>>>> more
>>>>>>> primitive piece of data in your query.
>>>>>>
>>>>>> # 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:
>>>>>> cookie['ID'] = random.randrange(0, 10000)
>>>>>> cookie['ID']['path'] = '/'
>>>>>> cookie['ID']['expires'] = 60*60*24*365 #this cookie will
>>>>>> expire in a month
>>>>>> cookieID = cookie.get('ID')
>>>>>> print( cookie )
>>>>>>
>>>>>>
>>>>>> In the above code i try to retrive the cookie form the visitor's
>>>>>> browser and if it does nto exist i create one.
>>>>>>
>>>>>>
>>>>>>
>>>>>> 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?
>>>>>>
>>>>>> Do you see something wrong?
>>>>>> Why cookie['ID'] retuned this string back and not just the number?
>>>>>>
>>>>>>
>>>>>
>>>>> Thanks for being patient. Where you have this:
>>>>>
>>>>> cookieID = cookie.get('ID')
>>>>>
>>>>> you actually want this:
>>>>>
>>>>> cookieID = cookie.get('ID').value
>>>>>
>>>>> --Ned.
>>>>
>>>>
>>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] File
>>>> "/home/nikos/public_html/cgi-bin/metrites.py", line 84, in <module>
>>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] cookieID =
>>>> cookie.get('ID').value
>>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]
>>>> AttributeError: 'NoneType' object has no attribute 'value'
>>>>
>>>
>>> Nikos: you know enough to understand what is going on here.
>>>
>>> This list will not serve you well if you take every error message and
>>> paste it into an email without trying to get to the bottom of it
>>> yourself. At the very least, a Google search on, "AttributeError:
>>> 'NoneType' object has no attribute 'value'" will find you some answers.
>>>
>>> I've said it before, I'll say it again: slow down.
>>>
>>> --Ned.
>>
>>
>> cookieID = cookie.get('ID').value
>>
>> is not returning what you said it will return
>>
>> and if cookie.get('ID') doenst exist it returns the error
>> AttributeError: 'NoneType' object has no attribute 'value'
>>
>> These are 2 problem.
>>
>> value aint being returned thw ehole Set-Cookie: ID=some_number is being
>> returned instead as tou cna see at http://superhost.gr/
>>
>> and the second problem is
>>
>> that if the cookie dosnt exist i get the error of: AttributeError:
>> 'NoneType' object has no attribute 'value'
>>
>> whne this line is tryign to be executed:
>> cookieID = cookie.get('ID').value
>>
>> How can i deal with thse 2 problems?
>>
> The best solution i cna think of is put the whole thing into a try: block
>
> try:
> cookieID = cookie.get('ID').value
> except:
> cookie['ID'] = random.randrange(0, 10000)
> cookie['ID']['path'] = '/'
> print( cookie )
> cookieID = cookie['ID'].value
>
> print( '''Content-type: text/html; charset=utf-8\n''' )
>
> print( cookieID )
> sys.exit(0)
>
> That will avoid the NoneType errot but:
>
> that still print out:
> Set-Cookie: ID=7413
>
> instead of just the number
>
Nikos, you are now answering your own emails. You are going too fast.
Slow down, think through a solution before writing another email. And
seriously, consider IRC, you will be able to have a conversation with
someone. The email pace doesn't suit you.
A better solution is to check to see if you got None:
if cookie.get('ID') is None:
# make a new cookie....
--Ned.
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 19:53 +0300 |
| Message-ID | <l2pg5g$h3g$1@dont-email.me> |
| In reply to | #56207 |
Στις 5/10/2013 7:42 μμ, ο/η Ned Batchelder έγραψε:
>
> A better solution is to check to see if you got None:
>
> if cookie.get('ID') is None:
> # make a new cookie....
I have tried everythign even wgat you suggested right now:
here is is:
# initialize cookie and retrieve cookie from clients broswer
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
if cookie.get('ID') is not None:
cookieID = cookie['ID'].value
else:
x = random.randrange(0, 10000)
cookie['ID'] = x
cookie['ID']['path'] = '/'
print( cookie )
cookieID = x
print( '''Content-type: text/html; charset=utf-8\n''' )
print( cookieID )
For some reason althogh the cookie does exist in my browser the returnd
value of cookieI D = cookie['ID'].value is always: Set-Cookie: ID=7482
instead of just the number.
But why? isnt value to return just the number?
You can see the result of the above code yourself at the top left when
you visit: http://superhost.gr
it always retursn the whole string instead of just the number...
why can we isolate th damn number only?
in the else i manages to isolate it but not when i try to retrive it.
[toc] | [prev] | [next] | [standalone]
| From | Zero Piraeus <z@etiol.net> |
|---|---|
| Date | 2013-10-05 12:06 -0300 |
| Message-ID | <mailman.749.1380987077.18130.python-list@python.org> |
| In reply to | #56190 |
:
On Sat, Oct 05, 2013 at 05:40:23PM +0300, Νίκος Αλεξόπουλος wrote:
> 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"
On Sat, Oct 05, 2013 at 05:47:54PM +0300, Νίκος Αλεξόπουλος wrote:
> 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"
Please don't give identical or near-identical replies to multiple
messages in the thread; other members of the list are either reading all
of your posts or none of them, so repeating yourself like this is only
going to irritate whoever is reading.
Since printing cookieID doesn't produce the output you expect, the
obvious next step is to look up the documentation for whatever kind of
object it is. You can find out its type with
type(cookieID)
... and then once you know that type (let's say for the sake of argument
it's a Biscuit object), find out about that type of object's attributes
either by googling for the docs or at the interpreter with
help(Biscuit)
As previously mentioned, there's likely to be some kind of 'value'
attribute that will return just the number you want.
-[]z.
--
Zero Piraeus: post scriptum
http://etiol.net/pubkey.asc
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 18:50 +0300 |
| Message-ID | <l2pcf6$f30$1@dont-email.me> |
| In reply to | #56196 |
Στις 5/10/2013 6:06 μμ, ο/η Zero Piraeus έγραψε:
> :
>
> On Sat, Oct 05, 2013 at 05:40:23PM +0300, Νίκος Αλεξόπουλος wrote:
>> 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"
>
> On Sat, Oct 05, 2013 at 05:47:54PM +0300, Νίκος Αλεξόπουλος wrote:
>> 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"
>
> Please don't give identical or near-identical replies to multiple
> messages in the thread; other members of the list are either reading all
> of your posts or none of them, so repeating yourself like this is only
> going to irritate whoever is reading.
>
> Since printing cookieID doesn't produce the output you expect, the
> obvious next step is to look up the documentation for whatever kind of
> object it is. You can find out its type with
>
> type(cookieID)
>
> ... and then once you know that type (let's say for the sake of argument
> it's a Biscuit object), find out about that type of object's attributes
> either by googling for the docs or at the interpreter with
>
> help(Biscuit)
>
> As previously mentioned, there's likely to be some kind of 'value'
> attribute that will return just the number you want.
nikos@superhost.gr [~/www/cgi-bin]# python
Python 3.3.2 (default, Aug 26 2013, 06:41:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, random
>>> from http import cookies
>>> cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
>>> cookieID = cookie.get('ID').value
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'value'
And if you go to my webpage http://superhost.gr at the top corner you
see that allthough i use this code to get the value of the retrieved
cookie or set the value if ti do
# initialize cookie and retrieve cookie from clients broswer
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
cookieID = cookie.get('ID').value
# if browser cookie does not exist, set it
if not cookieID:
cookie['ID'] = random.randrange(0, 10000)
cookie['ID']['path'] = '/'
cookie['ID']['expires'] = 60*60*24*365 #this cookie will expire in a month
print( cookie )
cookieID = cookie['ID'].value
print( '''Content-type: text/html; charset=utf-8\n''' )
print( cookieID )
sys.exit(0)
The output is: Set-Cookie: ID=1376
But how is this possible since we applied the .value attribute in the
cookie?
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-10-05 23:59 +1000 |
| Message-ID | <mailman.744.1380981591.18130.python-list@python.org> |
| In reply to | #56183 |
On Sat, Oct 5, 2013 at 11:38 PM, Νίκος Αλεξόπουλος
<nikos.gr33k@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!
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 17:24 +0300 |
| Message-ID | <l2p7ef$j06$1@dont-email.me> |
| In reply to | #56185 |
Στις 5/10/2013 4:59 μμ, ο/η Chris Angelico έγραψε:
> On Sat, Oct 5, 2013 at 11:38 PM, Νίκος Αλεξόπουλος
> <nikos.gr33k@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>
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-10-06 00:28 +1000 |
| Message-ID | <mailman.745.1380983299.18130.python-list@python.org> |
| In reply to | #56186 |
On Sun, Oct 6, 2013 at 12:24 AM, Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> wrote: > But i have given you the line that produces the error: The statement you quoted is an INSERT. The traceback quotes a SELECT. These are not the same line of code. You still have not shown us the actual line from the traceback. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-10-05 17:30 +0300 |
| Message-ID | <l2p7qr$j06$3@dont-email.me> |
| In reply to | #56187 |
Στις 5/10/2013 5:28 μμ, ο/η Chris Angelico έγραψε:
> On Sun, Oct 6, 2013 at 12:24 AM, Νίκος Αλεξόπουλος
> <nikos.gr33k@gmail.com> wrote:
>> But i have given you the line that produces the error:
>
> The statement you quoted is an INSERT. The traceback quotes a SELECT.
> These are not the same line of code. You still have not shown us the
> actual line from the traceback.
>
> ChrisA
>
Every mysql statemtns that involved cookieID fails.
in this example this:
# find the visitor record for the (saved) cID and current host
cur.execute('''SELECT * FROM visitors WHERE counterID = %s and cookieID
= %s''', (cID, cookieID) )
data = cur.fetchone() #cookieID is unique
--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.python
csiph-web