The Fix
pip install requests==2.0.2
Based on closed psf/requests issue #1663
Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.
def authenticate(self):
url = 'http://site.com/signIn'
data = { 'email': 'user', 'password': 'password'}
rsession = requests.Session()
rsession.post(url=url, data=data, verify=False)
self.context.cookies = rsession.cookies
rsession.close()
authenticate()
url = 'http://site.com/organizations.json'
resp = requests.get(url, cookies=self.context.cookies, verify=False)
Re-run: python2.7 test_requests.py
Option A — Upgrade to fixed release\npip install requests==2.0.2\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n
Why This Fix Works in Production
- Trigger: $ python2.7 test_requests.py
- Mechanism: That will be fixed in 2.0.2 by merging my pull request or some better way to fix it.
- Why the fix works: That will be fixed in 2.0.2 by merging my pull request or some better way to fix it. (first fixed release: 2.0.2).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 2.7 in real deployments (not just unit tests).
- Surfaces as: $ python2.7 test_requests.py
Proof / Evidence
- GitHub issue: #1663
- First fixed release: 2.0.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-04
- Confidence: 0.00
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.15
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I think it seems to be fault of my commit as @sigmavirus24 said. I already attached pull request for that issue in #1713. That will…”
“Thanks for raising this! We've known about these test failures for a while”
“In fact if you run httpbin locally and point the tests at it, they will pass. :grinning:”
“@Lukasa, I'm having similar issue right now: and this started to happen after 2.0.1 upgrade.”
Failure Signature (Search String)
- $ python2.7 test_requests.py
Error Message
Stack trace
Error Message
-------------
$ python2.7 test_requests.py
..EE..................................................................................
======================================================================
ERROR: test_DIGEST_AUTH_RETURNS_COOKIE (__main__.RequestsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_requests.py", line 285, in test_DIGEST_AUTH_RETURNS_COOKIE
assert r.cookies['fake'] == 'fake_value'
File "/tmp/requests/requests/cookies.py", line 256, in __getitem__
return self._find_no_duplicates(name)
File "/tmp/requests/requests/cookies.py", line 311, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='fake', domain=None, path=None"
======================================================================
ERROR: test_DIGEST_AUTH_SETS_SESSION_COOKIES (__main__.RequestsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_requests.py", line 295, in test_DIGEST_AUTH_SETS_SESSION_COOKIES
assert s.cookies['fake'] == 'fake_value'
File "/tmp/requests/requests/cookies.py", line 256, in __getitem__
return self._find_no_duplicates(name)
File "/tmp/requests/requests/cookies.py", line 311, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (
... (truncated) ...
Stack trace
Error Message
-------------
File "/Library/Python/2.7/site-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 327, in request
self.cookies = cookiejar_from_dict(cookies, cookiejar=self.cookies, overwrite=False)
File "/Library/Python/2.7/site-packages/requests/cookies.py", line 410, in cookiejar_from_dict
cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))
File "/Library/Python/2.7/site-packages/requests/cookies.py", line 256, in __getitem__
return self._find_no_duplicates(name)
File "/Library/Python/2.7/site-packages/requests/cookies.py", line 311, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose/suite.py", line 208, in run
self.setUp()
File "/Library/Python/2.7/site-packages/nose/suite.py", line 291, in setUp
self.setupContext(ancestor)
File "/Library/Python/2.7/site-packages/nose/suite.py", line 314, in setupContext
try_run(context, names)
File "/Library/Python/2.7/site-packages/nose/util.py", line 469, in try_run
return func()
... (my code trace goes here) it calls:
resp = requests.get(url, cookies=self.context.cookies, verify=False)
File "/Library/Python/2.7/site-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 327, in request
self.cookies = cookiejar_from_dict(cookies, cookiejar=self.cookies, overwrite=False)
File "/Library/Python/2.7/site-packages/requests/cookies.py", line 410, in cookiejar_from_dict
cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))
File "/Library/Python/2.7/site-packages/requests/cookies.py", line 256, in __getitem__
return self._find_no_duplicates(name)
File "/Library/Python/2.7/site-packages/requests/cookies.py", line 311, in _find_no_duplicates
raise KeyErr
... (truncated) ...
Minimal Reproduction
def authenticate(self):
url = 'http://site.com/signIn'
data = { 'email': 'user', 'password': 'password'}
rsession = requests.Session()
rsession.post(url=url, data=data, verify=False)
self.context.cookies = rsession.cookies
rsession.close()
authenticate()
url = 'http://site.com/organizations.json'
resp = requests.get(url, cookies=self.context.cookies, verify=False)
Environment
- Python: 2.7
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install requests==2.0.2
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/psf/requests/issues/1663
First fixed release: 2.0.2
When NOT to Use This Fix
- Do not use if it changes public behavior or if the failure cannot be reproduced.
Verify Fix
Re-run: python2.7 test_requests.py
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 2.0.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.