473,698 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookie.py troubles.

I'm confused about the way Cookie.load outputs cookies. Is there a way I
can tell it to give me the value of a key?

I set my cookie like this:

mycookie = Cookie.SimpleCo okie()
mycookie['key'] = "foobar"

print mycookie
print("Content-Type: text/html\n\n")
print("meow")

Now, to retrieve it, the documentation says I parse the HTTP_COOKIE
environment variable. Makes sense to me. But when I print it out I get
"Set-Cookie: key=foobar;". I was thinking of parsing it with cgi.parse_qs,
but even if i do print(mycookie. output(header=" ")) there's still a ; at
the end of the cookie.

Here's what I use to print them out:

cookie = Cookie.SimpleCo okie()
cookie.load(os. environ['HTTP_COOKIE'])

print("Content-Type: text/html\n\n")
print(mycookie. output(header=" "))

Output:

key=foobar;
Can anyone provide any advice?

- Ben Hearsum
Jul 18 '05 #1
1 3578
Ben Hearsum <bh******@myrea lbox.com> writes:
[...]
I set my cookie like this:

mycookie = Cookie.SimpleCo okie()
mycookie['key'] = "foobar"

print mycookie
print("Content-Type: text/html\n\n")
print("meow")

Now, to retrieve it, the documentation says I parse the HTTP_COOKIE
environment variable. Makes sense to me. But when I print it out I get
"Set-Cookie: key=foobar;". I was thinking of parsing it with cgi.parse_qs,
but even if i do print(mycookie. output(header=" ")) there's still a ; at
the end of the cookie.
Why do you want to parse Set-Cookie if you're writing a CGI script?

Set-Cookie is what the server sends to the client. HTTP_COOKIE is set
by the server, not by Python, to the value than was sent by the client
to the server. I guess SimpleCookie has a __str__ method that makes
it print out Set-Cookie: key=foobar; -- seems like useful behaviour.
Here's what I use to print them out:

cookie = Cookie.SimpleCo okie()
cookie.load(os. environ['HTTP_COOKIE'])
Yep, in comes the Cookie: header, I presume SimpleCookie parses it,
and then...

print("Content-Type: text/html\n\n")
print(mycookie. output(header=" "))
You send the cookie back to the client again.

Output:

key=foobar;


This seems to contradict what you said before ("key=foobar ;"
vs. "Set-Cookie: key=foobar;").

John
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3312
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the document.cookie variable combine all cookie key=value pairs? All of the examples I've seen discuss referencing a specific cookie. I don't see how this is done. Cookies are usually named by the domain. If I want to reference a specific cookie, do I...
4
3814
by: socialism001 | last post by:
I'm trying to store a value in a cookie but its not working. Can anyone see what I might be doing wrong. Thanks, Chris ~~~~~~~~~~~~~~~~~~ <script language="javascript"> if(document.cookie.indexOf("beenHere1=true")!=-1) else
9
4496
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored in a cookie and a small bullit shown in front of the hyperlink, so when I reload the page I can immediately see which hyperlinks I already visited that day.
7
14526
by: ehendrikd | last post by:
hi all i need some clarification on how the php session work in relation to cookies. we have a web site where users need to log in. a few of our users were having troubles with their browser clients having different levels of cookie security settings. i assumed a solution would be to have the php site use the session only, and set session.use_cookies to 0 in the php.ini file. after doing this, the session no longer persits after
1
999
by: Owen | last post by:
I have a web app that is a mixture of ASP and ASP.NET pages. Largely the only data passed between them is via the querystring, or by reading from a database. However there is a requirement for one part to communicate via a cookie. (Please dont ask me to go into why, I don't have time). In my ASP page, I created a cookie and put a value in it: Response.Cookies("MyCookieName") = "OriginalValue" Response.Cookies("MyCookieName").Expires...
0
982
by: csgraham74 | last post by:
Hi, Im trying to make changes to an appliction that i inherited. i have set several cookies with different small values from XML. i get to a piece of code where i response.redirect to another form. on the load event of the second form i have a breakpoint set in which i read the values of my cookies and they are set to 'nothing'. this is my problem. my cookie count = "10" (request.cookies.count) on the old form and on
2
1715
by: RootShell | last post by:
I have been experiencing a lot of troubles in reading a PHP COOKIE from javascript. if i write the cookie and read it in javascript in the same PHP file it works well, but if i write the cookie for instance in a Javascript(AJAX) called PHP file, the Javascript can read it. Any ideas why? This is a Javascript issue and not PHP, that's why im asking it here.
4
4119
by: gcervantes | last post by:
Hello, I am making a screen scraper, in other programs I have been able to log into a site, get the cookie, submit a form and read the results. However, this time I am in troubles, the site I need to log is using a local stored cookie or some info in it, since I can access OK from the IE, but when I log from the program I get some errors. I am using Fiddler to check the cookie values and the cookie I get from the site in the screen scraper...
9
1916
by: ziycon | last post by:
I am creating a cookie when a user clicks on a link and saving a value based on the link clicked, everytime the user goes to a different page i want the JS to check if the cookie already exists and use the value stored in it or if not to then create the cookie and save the selected value. The cookie can also change value based on the different links that the user clicks. Please find below what i have so far: function font_size(size) { var...
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.