Cookie not retrieving as it should in some cases

F

Ferrous Cranus

# retrieve cookie from client's browser otherwise set it
try:
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE', '') )
cookieID = cookie['ID'].value
except:
cookieID = str( time.time() )
cookieID = cookieID[-3:]

cookie['ID'] = cookieID


Many times i noticed that the script instead of retrieving the cookie ID value so to identify each visitor uniquely it insteads set its again.
The same think also happens when someone comes to superhost.gr via a link from anothwe webpage

can somebody tell me why this is happening?
is there some flaw in my code? Perhaps it can be written more efficiently?
 
Ö

Öþíôáò Ëáäïðñáêüðïõëïò

Ôç ÐáñáóêåõÞ, 2 ÌáÀïõ 2014 11:19:44 ð.ì.. UTC+3, ï ÷ñÞóôçò alister Ýãñáøå:
I had a similar issue when using Beaker middleware for WSGI which was
caused by me not specifying a location for the storage of the cookie
database.

I have tried also to set the path of the cookie and the expiration date of the cookie so for them not to impose a problem but yet the situation remains the same.

# retrieve cookie from client's browser otherwise set it
try:
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
cookieID = cookie['ID'].value
except KeyError:
cookieID = str( time.time() )
cookieID = cookieID[-3:]

cookie['ID'] = cookieID
cookie['ID']['path'] = '/'
cookie['ID']['expires'] = 3600 * 24 * 365 # 1 year from now
print( cookie.output() ) # send cookie to web client before headers

The cookie is properly set in my Chrome browser as i see form Chrome settings.

If someone visits for example ypsilandio.gr and then clicks superhost.gr from there then another cookie is also set with the same name 'ID' cusing a mess to the database hwich iam storing the visitor's based on the cookie i'am tryign to retrive from them.
 
Ö

Öþíôáò Ëáäïðñáêüðïõëïò

Ôç ÐáñáóêåõÞ, 2 ÌáÀïõ 2014 11:45:10 ð.ì.. UTC+3, ï ÷ñÞóôçò Öþíôáò Ëáäïðñáêüðïõëïò Ýãñáøå:
Ôç ÐáñáóêåõÞ, 2 ÌáÀïõ 2014 11:19:44 ð.ì. UTC+3, ï ÷ñÞóôçò alister Ýãñáøå:


I had a similar issue when using Beaker middleware for WSGI which was
caused by me not specifying a location for the storage of the cookie
database.



I have tried also to set the path of the cookie and the expiration date of the cookie so for them not to impose a problem but yet the situation remains the same.



# retrieve cookie from client's browser otherwise set it

try:

cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )

cookieID = cookie['ID'].value

except KeyError:

cookieID = str( time.time() )

cookieID = cookieID[-3:]



cookie['ID'] = cookieID

cookie['ID']['path'] = '/'

cookie['ID']['expires'] = 3600 * 24 * 365 # 1 year from now

print( cookie.output() ) # send cookie to web client before headers



The cookie is properly set in my Chrome browser as i see form Chrome settings.



If someone visits for example ypsilandio.gr and then clicks superhost.gr from there then another cookie is also set with the same name 'ID' cusing amess to the database hwich iam storing the visitor's based on the cookie i'am tryign to retrive from them.

Someone please suggest something?
This it troubling me for months.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top