473,396 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3557
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ken | last post by:
I am new to PHP. But this seems like a terrific language. I have been using JavaScript up to now but it looks like I will be changing to PHP. Seems to have more potential. I am confused about...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: Tyson Brown | last post by:
All We recently started writing a couple encrypted values to the user's cookie using FormsAuthentication.Encrypt. Such as: Dim tmpTicket1 As New FormsAuthenticationTicket(1, "TEST", Date.Now,...
6
by: Jason Collins | last post by:
There seems to be an inconsistency (bug?) in the way the Set-Cookie header is handled by the WebHeaderCollection. That is, the values of Set-Cookie, when an Expires is specified, contain the ","...
5
by: Miljana | last post by:
Hi, I have one problem with cookies in ASP.NET application. It seems that I can not retreive cookie from Request.Cookies collection. I put cookie in Response.Cookies collection, and after page...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
7
by: Nez | last post by:
Help needed! Hello, I have looked everywhere for a solution to my problem and this is pretty much my last resource. I have created a table in a span with the innerhtml command in my code behind....
29
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
8
by: LayneMitch via WebmasterKB.com | last post by:
I'm supposed to develop a page that asks info as form values and when you hit "submit" it takes you to a page that reads the values you entered into the first page and displays those values in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.