471,328 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,328 software developers and data experts.

help reading cookie values

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'
Jul 13 '07 #1
2 3424
On Jul 13, 3:08 pm, Sean <s...@horse101.comwrote:
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

Jul 13 '07 #2
ky******@gmail.com writes:
On Jul 13, 3:08 pm, Sean <s...@horse101.comwrote:
>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
[...snip cookie-sending and -receiving code...]
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
No, he doesn't want that -- that's for web clients, not web servers.

Wild guess: are you sending a domain attribute in your cookie (sniff
the HTTP traffic to find out, see below)? Try not doing that.

The cookie-receiving code above looks correct (I don't know about the
sending code, because I don't know what framework you're using, and
don't want to read that framework's code). Remember that things like
the cookie's domain and path have to match HTTP request's domain and
path for cookies to be *returned* by the browser to the server.
Simply having been *accepted* by the browser is not enough. The rules
are are fairly complicated, so KISS. You can use a network sniffer
like wireshark or tcpdump to record exactly what Set-Cookie: and
Cookie: headers are being sent, and compare with the domain name,
port, HTTP path and URL scheme (https/http) of the HTTP request that
your browser is making. If you still can't figure it out, post those
things here (change the domain name if you must, but keep the form of
everything strictly unchanged). Or simplify your situation to make it
easier to understand.

Another source of help would be the mailing list for the web framework
you're using.
John
Jul 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ken | last post: by
6 posts views Thread by Jason Collins | last post: by
5 posts views Thread by Miljana | last post: by
9 posts views Thread by Mike Reed | last post: by
7 posts views Thread by Nez | last post: by
29 posts views Thread by Jerim79 | last post: by
8 posts views Thread by LayneMitch via WebmasterKB.com | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.