[mod_python] question - Getting/Setting Cookies

David McNab david at rebirthing.co.nz
Thu Feb 12 22:03:16 EST 2004

Simon Willison wrote:

>> So my question is - is there any code for getting a Cookie object from 
>> the 'req' object?

> c = SimpleCookie()
> c.load(req.headers_in.get('cookie', ''))

There's no 'get' attribute in req.headers_in, at least not in mod_python 
v2.7.10 (Debian).

However, the following works:

     c = Cookie.SimpleCookie()
     if req.headers_in.has_key('cookie'):

Sorry for not asking before, but what's the cleanest way of putting the 
cookies into req.headers_out?

For me, the dictionary nature of req.headers_out is a stumbling block, 
because when I write the second and subsequent 'Set-Cookie' items, they 
overwrite the ones before.

Thanks again in advance for any help


Kind regards


leave this line intact so your email gets through my junk mail filter

More information about the Mod_python mailing list