On Apr 24, 12:41 pm, sophie_newbie <paulgeele...@gmail.com> wrote:
> On Apr 22, 8:38 pm, David <wizza...@gmail.com> wrote:
>
> > On Tue, Apr 22, 2008 at 6:21 PM,sophie_newbie<paulgeele...@gmail.com> wrote:
> > > 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!
|