[issue22296] cookielib uses time.time(), making incorrect checks of expiration times in cookies
Akira Li
report at bugs.python.org
Mon Sep 1 11:17:05 CEST 2014
Akira Li added the comment:
time.time() returns the current time in seconds since Epoch
it is neither local nor UTC time. It can be converted to both.
You can get local time using datetime.fromtimestamp(ts).
You can get UTC time using datetime.utcfromtimestamp(ts) or
to get an aware datetime object: datetime.fromtimestamp(ts, timezone.utc), where ts is the timestamp in seconds since Epoch.
I don't know whether there is an issue with cookie.is_expired() but it
is incorrect to use time.mktime() with UTC time tuple unless the local
time is UTC. To get the timestamp from a datetime object, you could
use .timestamp() method instead:
from datetime import datetime, timezone
now = datetime.now(timezone.utc) # the current time
seconds_since_epoch = now.timestamp()
seconds_since_epoch = time.time() # might be less precise
----------
nosy: +akira
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22296>
_______________________________________
More information about the Python-bugs-list
mailing list