From: Jeff Johnson <jeff@je...> - 2001-08-09 14:50:02
> Once you call response.addCookie(), you're done.
Well sorta.. unless the code has been changed in the last few weeks
it won't get saved to disk unless you do something like:
name = 'astiuid'
c = Cookie(name,locals()[name])
# The modern, standards based version doesn't seem to work with
#c.setMaxAge(30*24*60*60) # Doesn't cause the cookie to be saved to
# The old, non-standard way (expires) does seem to work with
#c._cookie['expires'] = "Friday, 27-Apr-01 11:11:11 GMT" # Does get
saved to disk.
expirationDate = DateTime.now() +
c._cookie['expires'] = expirationDate.Format("%A, %d-%b-%y %H:%M:%S
> Gary Perez wrote:
> >Hi, all.
> >Kicking OneShot.cgi around a bit, and I'm doing okay for now except
> >can't seem to figure out how to set a cookie that gets written to
> >client's cookie file.
> >I've been through the modules, trying to construct the right
> body for my
> >method (whose class subclasses only 'Page'). Here are relevant (and
> >probably incorrectly-used) parts of the module for your perusal:
> >from Webkit.Page import Page
> >from WebKit.Cookie import Cookie
> >from Webkit.HTTPResponse import HTTPResponse
> >class FormHandler(Page):
> > def setACookie(self):
> > astiCookie = Cookie('astiuid', 12345)
> > astiCookie.setComment('Your unique ASTi ID')
> > astiCookie.setDomain('asti-usa.com')
> > astiCookie.setPath('/')
> > HTTPResponse().addCookie(astiCookie)
> >... and now what? If I try
> HTTPResponse().deliver(astiCookie) it throws
> >an exception saying the cookie instance has no attribute
> '_session' or
> >HTTPResponse().deliver('astiuid') throws AttributeError on
> >I've tried just about everything I can think of, guided by the
> >documentation in the WebKit modules, to no avail. Can
> someone spell it
> >out for me like I'm an idiot--which I must be if I can't set a damn
> >cookie! ;)
This cookie topic comes up every few months so you're not the only one
Get latest updates about Open Source Projects, Conferences and News.