473,729 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6454
"Vlad Dogaru" <dd****@gmail.c omwrites:
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.c omwrites:
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.c omwrites:
[...]
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.c omwrites:
[...]
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
4348
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? Regards,
1
3248
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 got any code out there that will set and retrieve > cookie values that have the key/subKey structure? Using the code provided below, examine
1
3475
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 modified from The JavaScript Source) is broken between domains, because when I click my "store" link that should read the cookie and send me to store1.mydomain.com or storeN.mydomain.com I get the default template store.
2
2583
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 browser cache setting (and OS), the program behaves differently. This is how it should work: 1. The client program opens a webbrowser control, using navigate2 method to post xml data to my aspx pages, eg abc.aspx
2
3733
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 a DLL, which is why I use HttpContext)... HttpCookie cookie = new HttpCookie("fred", "ferret");
2
1408
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-------------- <% response.cookies("prefs")("make")="Aston Martin" response.cookies("prefs")("model")="Vanquish"
0
1182
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-------------- <% response.cookies("prefs")("make")="Aston Martin" response.cookies("prefs")("model")="Vanquish"
8
1821
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 cookie may be named "webwise". One technical description of the system and this aspect can be found via: http://www.lightbluetouchpaper.org/2008/04/04/the-phorm-webwise-system/ or if you want to go straight to the report:
5
1690
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
8917
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
9426
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
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4525
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.