Problem reading HTTP_COOKIE
Jack Hatterly
jackhatterly at hotmail.com
Fri Aug 12 17:55:36 EDT 2011
> Date: Fri, 12 Aug 2011 21:29:25 +0100
> Subject: Re: Problem reading HTTP_COOKIE
> From: rosuav at gmail.com
> To: python-list at python.org
>
> I assume that what you mean is that it prints "None" even after you
> hit F5 to reload the page, as the first run of the script will never
> have a cookie.
>
> Your script is now not actually setting any cookie. What cookie are
> you seeing in your browser? It may be something created and consumed
> by your framework, somewhere.
But my script *is* setting a cookie. I just sent a stripped-down version of the script earlier. Here's the entire script:
#! /usr/bin/python
import string
import os
import datetime, Cookie, random
import time
import os
def parse_cookie():
ourTime = str(time.time())
environ = os.environ
cookie = environ.get('HTTP_COOKIE', '')
if cookie == '':
cookie = string.replace(ourTime, '.', '')
cookie = Cookie.SimpleCookie()
expiration = datetime.datetime.now() + datetime.timedelta(days=30)
cookie['lastvisit'] = random.randint(1,999999999999)
cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60
cookie['lastvisit']['path'] = '/var/www/html/my_site/clients/Millenium/'
cookie['lastvisit']['comment'] = random.randint(1,999999999999)
cookie['lastvisit']['domain'] = '.www.my_site.com'
cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60
cookie['lastvisit']['secure'] = ''
cookie['lastvisit']['version'] = 1
c = Cookie.SimpleCookie()
c.load(cookie)
cookiedict = {}
for key in c.keys():
cookiedict[key] = c.get(key).value
print c
print 'Content-Type: text/html\n'
print '<html><body>'
print '</body></html>'
if __name__ == "__main__":
parse_cookie()
You see, every time when the cookie is read it comes back None which gets translated to '' and then the cookie is re-baked. *NOT* what I want!! I can see the cookie in my browser.
TIA,
Jack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110812/9162f0de/attachment-0001.html>
More information about the Python-list
mailing list