The Fix
pip install requests==2.27.0
Based on closed psf/requests issue #2811 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -24,6 +24,7 @@
from .packages.urllib3.exceptions import HTTPError as _HTTPError
from .packages.urllib3.exceptions import MaxRetryError
+from .packages.urllib3.exceptions import NewConnectionError
from .packages.urllib3.exceptions import ProxyError as _ProxyError
from .packages.urllib3.exceptions import ProtocolError
Option A — Upgrade to fixed release\npip install requests==2.27.0\nWhen NOT to use: This fix should not be applied if the behavior of treating NewConnectionError as a timeout is desired.\n\n
Why This Fix Works in Production
- Trigger: requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
- Mechanism: NewConnectionError is incorrectly treated as a timeout instead of a connection error
- Why the fix works: Resolves issue #2811 by ensuring that NewConnectionErrors are not treated as timeouts, aligning the error handling with the previous behavior in the 2.X series. (first fixed release: 2.27.0).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- NewConnectionError is incorrectly treated as a timeout instead of a connection error
- Surfaces as: requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
Proof / Evidence
- GitHub issue: #2811
- Fix PR: https://github.com/psf/requests/pull/2812
- First fixed release: 2.27.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-07
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.75
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hmm, looks like urllib3 changed how it wrapped this exception. Let me see if I can find where this problem got introduced.”
“I suspect shazow/urllib3#703 may have introduced a new exception type that urllib3 treats differently to socket.error.”
“@Lukasa if the OpenStack gate is indicative of anything, it's between 1.10.4 and 1.11”
“Looks to me like it was actually done in 1.12: NewConnectionError is a subclass of ConnectTimeoutError, whereas previously socket.error wouldn't have been.”
Failure Signature (Search String)
- requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
Error Message
Stack trace
Error Message
-------------
requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))
What Broke
Users experience incorrect timeout exceptions when accessing unknown URLs.
Why It Broke
NewConnectionError is incorrectly treated as a timeout instead of a connection error
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install requests==2.27.0
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/psf/requests/pull/2812
First fixed release: 2.27.0
Last verified: 2026-02-07. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the behavior of treating NewConnectionError as a timeout is desired.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
- Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
- Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.
Version Compatibility Table
| Version | Status |
|---|---|
| 2.27.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.