Cookie.py troubles.

Ben Hearsum bhearsum at myrealbox.com
Sun Jul 27 22:07:25 CEST 2003


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.SimpleCookie()
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.SimpleCookie()
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




More information about the Python-list mailing list