This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients Scott.Wimer, demian.brecht, jcea, martin.panter, orsenthil, r.david.murray, terry.reedy, xtreak
Date 2019-04-25.09:05:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> Karthikeyan, it looks like your test will pass even when the bug is not fixed. A test calling code that writes error message does not necessarily mean the test itself will fail, I don’t think.

You are right. Sorry, I got mislead by the Exception message and didn't notice the test was passing. The below patch to master ensures the test passes by asserting expires in the cookie. If @demian.brecht haven't had a chance to make a PR then I can try converting the to a PR adding them as co-author.

diff --git a/Lib/http/ b/Lib/http/
index db82382357..07105a7c20 100644
--- a/Lib/http/
+++ b/Lib/http/
@@ -1590,6 +1590,7 @@ class CookieJar:
     def make_cookies(self, response, request):
         """Return sequence of Cookie objects extracted from response object."""
         # get cookie-attributes for RFC 2965 and Netscape protocols
+        self._policy._now = self._now = int(time.time())
         headers =
         rfc2965_hdrs = headers.get_all("Set-Cookie2", [])
         ns_hdrs = headers.get_all("Set-Cookie", [])
@@ -1672,8 +1673,6 @@ class CookieJar:
         _debug("extract_cookies: %s",
-            self._policy._now = self._now = int(time.time())
             for cookie in self.make_cookies(response, request):
                 if self._policy.set_ok(cookie, request):
                     _debug(" setting cookie: %s", cookie)
diff --git a/Lib/test/ b/Lib/test/
index 22bf41cf1d..ad3364c950 100644
--- a/Lib/test/
+++ b/Lib/test/
@@ -585,6 +585,14 @@ class CookieTests(unittest.TestCase):
         # if expires is in future, keep cookie...
         c = CookieJar()
         future = time2netscape(time.time()+3600)
+        headers = ["Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires={0}".format(future)]
+        req = urllib.request.Request("")
+        res = FakeResponse(headers, "")
+        cookies = c.make_cookies(res, req)
+        self.assertEqual(len(cookies), 1)
+        self.assertEqual(time2netscape(cookies[0].expires), future)
         interact_netscape(c, "", 'spam="bar"; expires=%s' %
         self.assertEqual(len(c), 1)

Failure without patch : 

./python.exe -m unittest -v test.test_http_cookiejar.CookieTests.test_expires
test_expires (test.test_http_cookiejar.CookieTests) ... /Users/karthikeyansingaravelan/stuff/python/cpython/Lib/http/ UserWarning: http.cookiejar bug!
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/http/", line 1616, in make_cookies
    ns_cookies = self._cookies_from_attrs_set(
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/http/", line 1574, in _cookies_from_attrs_set
    cookie = self._cookie_from_cookie_tuple(tup, request)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/http/", line 1546, in _cookie_from_cookie_tuple
    elif expires <= self._now:
AttributeError: 'CookieJar' object has no attribute '_now'


FAIL: test_expires (test.test_http_cookiejar.CookieTests)
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/", line 593, in test_expires
    self.assertEqual(len(cookies), 1)
AssertionError: 0 != 1

Ran 1 test in 0.017s

FAILED (failures=1)
Date User Action Args
2019-04-25 09:05:07xtreaksetrecipients: + xtreak, terry.reedy, jcea, orsenthil, r.david.murray, Scott.Wimer, martin.panter, demian.brecht
2019-04-25 09:05:07xtreaksetmessageid: <>
2019-04-25 09:05:07xtreaklinkissue12144 messages
2019-04-25 09:05:06xtreakcreate