[mod_python] Cookie problem

Eric St-Jean esj at wwd.ca
Sat Feb 5 09:43:15 EST 2005


dagurp at heimsnet.is wrote:

>On Friday 04 February 2005 11:06 am, dagurp at heimsnet.is wrote:
>  
>
>>>Hi,
>>>I create a cookie and set it to expire in 2 weeks like this:
>>>
>>> cookie = Cookie.Cookie('foo', bar)
>>> cookie.expires = time() + 1209600  # 2 weeks
>>> Cookie.add_cookie(req, cookie)
>>>
>>>      
>>>
(snip)

>>The expires attribute is a property whose value is >checked upon setting to 
>>be in format "Wdy, DD-Mon-YYYY HH:MM:SS GMT" (as >dictated per Netscape 
>>cookie specification), or a numeric value >representing time in seconds 
>>since beginning of epoch (which will be >automatically correctly converted 
>>to GMT time string). An invalid expires value will >raise ValueError.
>>
>>Therefore, you cannot set it to time.time().  You'll >need to create a 
>>strftime string for it.
>>    
>>
>
>If you read it more carefully you'll see that you can use a numeric value. In
>fact that's what they do in the examples. I did try to use the Netscape format
>however but it always gave me errors.
>
>_
>

but you're using time.time(), which returns a float. the doc snippet 
above doesn't say it explicitely, but it sounds like it want an integer 
number of seconds. what if you do

cookie.expires = int(time()) + 1209600

?


-- 




More information about the Mod_python mailing list