473,379 Members | 1,367 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,379 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 3554
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.