Calling Cookie Values

Victor Subervi victorsubervi at gmail.com
Tue Dec 15 14:12:53 EST 2009


On Tue, Dec 15, 2009 at 2:36 PM, MRAB <python at mrabarnett.plus.com> wrote:

> You've just created a cookie, but are trying to get a value without
> having set it first!
>

LOL! Rewrote code thus:

  cookie = os.environ.get('HTTP_COOKIE')
  if not cookie:
    cookie = Cookie.SimpleCookie()
    cExpires, cPath, cComment, cDomain, cMaxAge, cVersion = myCookie()
    cookie['lastvisit'] = str(time.time())
    cookie['lastvisit']['expires'] = cExpires
    cookie['lastvisit']['path'] = cPath
    cookie['lastvisit']['comment'] = cComment
    cookie['lastvisit']['domain'] = cDomain
    cookie['lastvisit']['max-age'] = cMaxAge
    cookie['lastvisit']['version'] = cVersion
    cookieFlag = 'new'
  else:
    cookieFlag = 'old'
    print cookie['lastvisit']['expires'].value

Got this error:

 /var/www/html/angrynates.com/cart/cart.py
  191 </html>
  192 '''
  193
  194 cart()
  195
cart = <function cart>
 /var/www/html/angrynates.com/cart/cart.py in cart()
   31   else:
   32     cookieFlag = 'old'
   33     print cookie['lastvisit']['expires'].value
   34 #  Don't know what to do with this. It's for when client won't accept
cookies
   35 #  sessionDir = os.environ['DOCUMENT_ROOT'] + '/tmp/.session'
cookie = 'lastvisit=1260898013.65; lastvisit=1260898315.01', ].value
undefined

TypeError: string indices must be integers
      args = ('string indices must be integers',)

Please advise.
TIA,
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091215/49cc1ff6/attachment-0001.html>


More information about the Python-list mailing list