473,325 Members | 2,480 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,325 software developers and data experts.

Getting and Setting Cookies

Hello,

I am trying to use cookies and Python to create a simple login example.
But I am very disoriented at the existence of two cookie libraries,
namely Cookie and cookielib. I have seen examples of setting cookies
(although I am still not sure about timestamps and cookie lifespan),
but no reference to getting the currently set cookies. For instance, I
want to see if there is any 'user' value, to check whether the user has
logged in. Please, enlighten me.

Thanks in advance,
Vlad

Jul 18 '06 #1
4 6426
"Vlad Dogaru" <dd****@gmail.comwrites:
I am trying to use cookies and Python to create a simple login example.
But I am very disoriented at the existence of two cookie libraries,
namely Cookie and cookielib. I have seen examples of setting cookies
[...]

From the cookielib docs:

http://docs.python.org/lib/module-cookielib.html

| The cookielib module defines classes for automatic handling of HTTP
| cookies. It is useful for accessing web sites that require small
| pieces of data - cookies - to be set on the client machine by an HTTP
| response from a web server, and then returned to the server in later
| HTTP requests.

(note the *accessing* there)

[...]

| Module Cookie: HTTP cookie classes, principally useful for server-side
| code. The cookielib and Cookie modules do not depend on each
| other.
Module cookielib is for web client code (writing code that works like
a browser). Module Cookie is for server-side code (writing code to
make a web site work). You don't make it entirely clear which you're
doing, but it sounds like the latter.
John
Jul 18 '06 #2

John J. Lee wrote:
"Vlad Dogaru" <dd****@gmail.comwrites:
I am trying to use cookies and Python to create a simple login example.
But I am very disoriented at the existence of two cookie libraries,
namely Cookie and cookielib. I have seen examples of setting cookies
[...]

From the cookielib docs:

http://docs.python.org/lib/module-cookielib.html

| The cookielib module defines classes for automatic handling of HTTP
| cookies. It is useful for accessing web sites that require small
| pieces of data - cookies - to be set on the client machine by an HTTP
| response from a web server, and then returned to the server in later
| HTTP requests.

(note the *accessing* there)

[...]

| Module Cookie: HTTP cookie classes, principally useful for server-side
| code. The cookielib and Cookie modules do not depend on each
| other.
Module cookielib is for web client code (writing code that works like
a browser). Module Cookie is for server-side code (writing code to
make a web site work). You don't make it entirely clear which you're
doing, but it sounds like the latter.
I am trying to write a simple login script. I understand (or rather I
think I understand) how to set a cookie with the Cookie module. My
problem is getting the cookies that are currently set. How can I do
that?

Jul 19 '06 #3
"Vlad Dogaru" <dd****@gmail.comwrites:
[...]
I am trying to write a simple login script. I understand (or rather I
think I understand) how to set a cookie with the Cookie module. My
problem is getting the cookies that are currently set. How can I do
that?
You still haven't explicitly said that you're writing server-side
code. If you are:

IIRC, you .load() it from the HTTP header value, then you use it as a
mapping (though, oddly, that seems undocumented, except in the
"Example" section of the docs). A working CGI-based example (written
in a rather retro style for ease of deployment):

http://codespeak.net/svn/wwwsearch/C...cookietest.cgi
If you want to iterate over all cookies using module Cookie (that
script does not), use .keys(), .values() or .items() on your
SimpleCookie instance (it's also a little odd that instances of class
SimpleCookie do not represent a single cookie, but a collection of
cookies).
John
Jul 19 '06 #4
John J. Lee wrote:
"Vlad Dogaru" <dd****@gmail.comwrites:
[...]
I am trying to write a simple login script. I understand (or rather I
think I understand) how to set a cookie with the Cookie module. My
problem is getting the cookies that are currently set. How can I do
that?

You still haven't explicitly said that you're writing server-side
code. If you are:

IIRC, you .load() it from the HTTP header value, then you use it as a
mapping (though, oddly, that seems undocumented, except in the
"Example" section of the docs). A working CGI-based example (written
in a rather retro style for ease of deployment):

http://codespeak.net/svn/wwwsearch/C...cookietest.cgi
If you want to iterate over all cookies using module Cookie (that
script does not), use .keys(), .values() or .items() on your
SimpleCookie instance (it's also a little odd that instances of class
SimpleCookie do not represent a single cookie, but a collection of
cookies).
That's pretty much what I was trying to find out. Thanks for the
pointer.

Vlad

Jul 20 '06 #5

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

Similar topics

4
by: Sims | last post by:
Hi, Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS $HTTP_GET_VARS = 'bar'? If yes, why? and how can i pass value between one page and the other without using the url?...
1
by: Mike | last post by:
I got the code below from an earlier post but I can't get it to work (I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have code that works for cookies with keys? > Anyone...
1
by: Jose Olivas | last post by:
I am setting a cookie on a subdomain: http://store1.mydomain.com Then the store takes me to a shopping cart that is at: http://shopping.mydomain.com Somewhere the following code (taken and...
2
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the...
2
by: Alan Silver | last post by:
Hello, I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value. For example (this is running in...
2
by: rjoseph | last post by:
Hi Guys I think I have a really easy one for you. I am currently using the following script to store information in cookies: -------------SCRIPT-------------- <%...
0
by: rjoseph | last post by:
Hi Guys I think I have a really easy one for you. I am currently using the following script to store information in cookies: -------------SCRIPT-------------- <%...
8
by: WiW | last post by:
FYI: It appears that Phorm (a targeted advertising system which taps into ISP networks) will be setting its own persistent cookie for most every website the user visits. It appears as though the...
5
by: sophie_newbie | last post by:
Does anyone know how to do this? I can't seem to make it work. I'm using: c = Cookie.SimpleCookie() c = "unamepwordwhatever" c.expires = time.time() + 300 print c
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.