<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
> Date: Fri, 12 Aug 2011 21:29:25 +0100<br><div>> Subject: Re: Problem reading HTTP_COOKIE<br>> From: rosuav@gmail.com<br>> To: python-list@python.org<br>> <br>> I assume that what you mean is that it prints "None" even after you<br>> hit F5 to reload the page, as the first run of the script will never<br>> have a cookie.<br>> <br>> Your script is now not actually setting any cookie. What cookie are<br>> you seeing in your browser? It may be something created and consumed<br>> by your framework, somewhere.<br><br>But my script *is* setting a cookie. I just sent a stripped-down version of the script earlier. Here's the entire script:<br><br>#! /usr/bin/python<br><br>import string<br>import os<br>import datetime, Cookie, random<br>import time<br>import os<br><br>def parse_cookie():<br> ourTime = str(time.time())<br> environ = os.environ<br> cookie = environ.get('HTTP_COOKIE', '')<br> if cookie == '':<br> cookie = string.replace(ourTime, '.', '')<br> cookie = Cookie.SimpleCookie()<br> expiration = datetime.datetime.now() + datetime.timedelta(days=30)<br> cookie['lastvisit'] = random.randint(1,999999999999)<br> cookie['lastvisit']['expires'] = 30 * 24 * 60 * 60<br> cookie['lastvisit']['path'] = '/var/www/html/my_site/clients/Millenium/'<br> cookie['lastvisit']['comment'] = random.randint(1,999999999999)<br> cookie['lastvisit']['domain'] = '.www.my_site.com'<br> cookie['lastvisit']['max-age'] = 30 * 24 * 60 * 60<br> cookie['lastvisit']['secure'] = ''<br> cookie['lastvisit']['version'] = 1<br> c = Cookie.SimpleCookie()<br> c.load(cookie)<br> cookiedict = {}<br> for key in c.keys():<br> cookiedict[key] = c.get(key).value<br> print c<br> print 'Content-Type: text/html\n'<br><br> print '<html><body>'<br> print '</body></html>'<br><br>if __name__ == "__main__":<br> parse_cookie()<br><br>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.<br>TIA,<br>Jack<br></div> </div></body>
</html>