Cookie not retrieving as it should in some cases

Discussion in 'Python' started by Ferrous Cranus, May 2, 2014.

  1. # 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?
     
    Ferrous Cranus, May 2, 2014
    #1
    1. Advertisements

  2. Ôç ÐáñáóêåõÞ, 2 ÌáÀïõ 2014 11:19:44 ð.ì.. UTC+3, ï ÷ñÞóôçò alister Ýãñáøå:
    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.
     
    Öþíôáò Ëáäïðñáêüðïõëïò, May 2, 2014
    #2
    1. Advertisements

  3. Ôç ÐáñáóêåõÞ, 2 ÌáÀïõ 2014 11:45:10 ð.ì.. UTC+3, ï ÷ñÞóôçò Öþíôáò Ëáäïðñáêüðïõëïò Ýãñáøå:
    Someone please suggest something?
    This it troubling me for months.
     
    Öþíôáò Ëáäïðñáêüðïõëïò, May 2, 2014
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.