help reading cookie values
kyosohma at gmail.com
kyosohma at gmail.com
Fri Jul 13 16:29:55 EDT 2007
On Jul 13, 3:08 pm, Sean <s... at horse101.com> wrote:
> I am trying to read a cookie I set but I am not sure if I really set
> it correctly or I am not reading it correctly. I was given the
> following instructions to set the cookie. It appears to be working
> because in Firefox browser I see the cookie listed for my domain
>
> > you set a cookie in a pythonscript like:
> > context.REQUEST.RESPONSE.setCookie('cookie_name', 'some value',
> > expires=(DateTime() + 365).toZone('GMT').rfc822(), path='/')
>
> I have been searching everywhere to find information on reading the
> cookie value that I set. I used the following code I found which
> returns 'no cookiez' in spite of the fact that I see the cookie in my
> browser's cookie listing. I must be doing something wrong in the way
> I am testing for its existence
>
> import Cookie
> import os
> thiscookie = Cookie.SimpleCookie()
>
> if 'HTTP_COOKIE' in os.environ:
> #if os.environ.has_key('HTTP_COOKIE'): I tried this way also
>
> thiscookie.load(os.environ['HTTP_COOKIE'])
>
> a_code = thiscookie['my_cookie'].value
>
> return a_code
>
> else:
>
> return 'no cookiez'
This site looks like it has some good information on Cookie handling
(see "cookielib and ClientCookie Example" section:
http://www.voidspace.org.uk/python/recipebook.shtml
Mike
More information about the Python-list
mailing list