473,503 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting expirty data on a cookie

Does anyone know how to do this? I can't seem to make it work.

I'm using:

c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c.expires = time.time() + 300
print c
This doesn't seem to work, so I'm assuming isn't the correct way to
set an expiry data? Anyone able to help me out here?

Thanks!
Jun 27 '08 #1
5 1679
On Tue, Apr 22, 2008 at 6:21 PM, sophie_newbie <pa**********@gmail.comwrote:
Does anyone know how to do this? I can't seem to make it work.

I'm using:

c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c.expires = time.time() + 300
print c
This doesn't seem to work, so I'm assuming isn't the correct way to
set an expiry data? Anyone able to help me out here?
You're probably looking for cookielib.Cookie
Jun 27 '08 #2
On Apr 22, 8:38 pm, David <wizza...@gmail.comwrote:
On Tue, Apr 22, 2008 at 6:21 PM,sophie_newbie<paulgeele...@gmail.comwrote:
Does anyone know how to do this? I can't seem to make it work.
I'm using:
c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c.expires = time.time() + 300
print c
This doesn't seem to work, so I'm assuming isn't the correct way to
set an expiry data? Anyone able to help me out here?

You're probably looking for cookielib.Cookie
I don't think so, to give you a more complete picture, if I run this
code:
import Cookie
import time
c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c.expires = time.time() + 300
print c
This codes gives an output of:

"Set-Cookie: data=unamepwordwhatever"

As in there is no mention of an expiry date, when surely there should
be?

Thanks for any advice.
Jun 27 '08 #3
On Apr 24, 12:41 pm, sophie_newbie <paulgeele...@gmail.comwrote:
On Apr 22, 8:38 pm, David <wizza...@gmail.comwrote:
On Tue, Apr 22, 2008 at 6:21 PM,sophie_newbie<paulgeele...@gmail.comwrote:
Does anyone know how to do this? I can't seem to make it work.
I'm using:
c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c.expires = time.time() + 300
print c
This doesn't seem to work, so I'm assuming isn't the correct way to
set an expiry data? Anyone able to help me out here?
You're probably looking for cookielib.Cookie

I don't think so, to give you a more complete picture, if I run this
code:

import Cookie
import time
c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c.expires = time.time() + 300
print c

This codes gives an output of:

"Set-Cookie: data=unamepwordwhatever"

As in there is no mention of an expiry date, when surely there should
be?

Thanks for any advice.
Ok this seems to work:

import Cookie
import time
c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c['data']['expires'] = 30 * 24 * 60 * 60
print c

Gives an output of:

"Set-Cookie: data=unamepwordwhatever; expires=Sat, 24-May-2008
12:11:36 GMT"

Bizarre that this information was so hard to find!
Jun 27 '08 #4
import Cookie
import time
c = Cookie.SimpleCookie()
c['data'] = "unamepwordwhatever"
c['data']['expires'] = 30 * 24 * 60 * 60
print c

Gives an output of:

"Set-Cookie: data=unamepwordwhatever; expires=Sat, 24-May-2008
12:11:36 GMT"
Hi again. I didn't see your replies until now.

Disclaimer: I've never worked with cookies before, I'm just going by
the rfc, python docs, and wikipedia.

I think the confusion exists because the Cookie module has an unusual
definition of cookies. What we call cookies (key + value +
attributes), the Cookie module calls a Morsel. What the Cookie module
calls a cookie is in fact the collection of Set-Cookie headers that
will be sent by the server.

So for code like this:

c = Cookie.SimpleCookie()
c['data1'] = 123
c['data2'] = 456

the server will output 2 cookies like this:

Set-Cookie: data1=123
Set-Cookie: data2=456

This is why when you want to set the expiry date for one of the
cookies, you need syntax like this:

c['data2']['expires'] = 30 * 24 * 60 * 60

Another note: 'expires' is apprantly a legacy attribute for early
Netscape browsers. The RFC and python source comments suggest that you
use 'Max-Age' instead.

I think that the Cookie module author wanted to represent http state
as a python dictionary, but chose an unfortunate name for the class.
Also, the example page doesn't go into detail about setting
attributes.

David.
Jun 27 '08 #5
On 2008-04-25, David <wi******@gmail.comwrote:
Another note: 'expires' is apprantly a legacy attribute for early
Netscape browsers. The RFC and python source comments suggest that you
use 'Max-Age' instead.
Theoretically, yes. In practice, no. *Nobody* uses the new-style
cookies, everyone uses Netscape ones.
Jun 27 '08 #6

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

Similar topics

2
9158
by: bagsmode | last post by:
Hi, I'm trying to set a session cookie and then redirect, however I get the error: Status: 302 Moved Location: /index.cgi I thought I recall getting an error like this when I first tried...
4
3791
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">...
1
3447
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...
0
1456
by: Chris | last post by:
Hi all, I'm having trouble setting an authorization cookie from a web service. I need to set an authorization cookie on the client machine when the proper soap header is sent with...
2
2555
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...
6
16412
by: somaboy mx | last post by:
Hello I need people to be able to complete long text blocks in my cms before their session times out. From the php documentation I gather that ini directive session.gc_maxlifetime would be the...
4
6442
by: Vlad Dogaru | last post by:
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...
1
6441
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
4
7297
by: SevDer | last post by:
Hi, I've done some coding in my web application however right now for an unknown reason my asp.net 2.0 site is not setting asp.net_sessionid cookie and as a result, I am losing the session data...
0
7205
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,...
0
7353
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...
1
7011
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...
0
5596
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,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
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...

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.