Jump to solution
Verify

The Fix

pip install urllib3==1.26.20

Based on closed urllib3/urllib3 issue #3374 · 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%.

Jump to Verify Open PR/Commit
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Fixed ResourceWarning on CONNECT with Python < 3.11.4 by backporting https://github.com/python/cpython/issues/103472. diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py index 9f47b1b25e..7cbef7d5a9 100644
repro.py
from http.server import BaseHTTPRequestHandler from socketserver import ThreadingTCPServer class HTTPConnectProxyHandler(BaseHTTPRequestHandler): protocol_version = 'HTTP/1.1' default_request_version = 'HTTP/1.1' def do_CONNECT(self): self.send_response(407) self.send_header('Proxy-Authenticate', 'Basic') self.end_headers() ThreadingTCPServer(('127.0.0.1', 55556), HTTPConnectProxyHandler).serve_forever()
verify
Re-run: python3.10 -Werror test.py
fix.md
Option A — Upgrade to fixed release\npip install urllib3==1.26.20\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: $ python3.10 -Werror test.py
  • Mechanism: ResourceWarnings were not properly handled for HTTP CONNECT responses with status 407 in urllib3
  • Why the fix works: Backports a fix for ResourceWarnings on CONNECT with Python versions lower than 3.11.4, addressing unclosed socket warnings after receiving a 407 response from an HTTP CONNECT proxy. (first fixed release: 1.26.20).
Production impact:
  • 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

  • Shows up under Python 3.10 in real deployments (not just unit tests).
  • ResourceWarnings were not properly handled for HTTP CONNECT responses with status 407 in urllib3
  • Surfaces as: $ python3.10 -Werror test.py

Proof / Evidence

  • GitHub issue: #3374
  • Fix PR: https://github.com/urllib3/urllib3/pull/3252
  • First fixed release: 1.26.20
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.29

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Perhaps related to https://github.com/urllib3/urllib3/pull/3252?”
@coletdjnz · 2024-05-03 · source
“(I'm going to consider that #3252 fixed it until I hear otherwise, since this is the exact same issue.)”
@pquentin · 2024-08-13 · source
“> @coletdjnz can you repeat on 3.11.3? I don't have 3.11.3 on hand, but testing with 3.10.14 on main branch it appears to be fixed…”
@coletdjnz · 2024-09-08 · source

Failure Signature (Search String)

  • $ python3.10 -Werror test.py

Error Message

Stack trace
error.txt
Error Message ------------- $ python3.10 -Werror test.py Traceback (most recent call last): File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connectionpool.py", line 779, in urlopen self._prepare_proxy(conn) File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connectionpool.py", line 1048, in _prepare_proxy conn.connect() File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connection.py", line 633, in connect self._tunnel() # type: ignore[attr-defined] File "/usr/lib64/python3.10/http/client.py", line 925, in _tunnel raise OSError(f"Tunnel connection failed: {code} {message.strip()}") OSError: Tunnel connection failed: 407 Proxy Authentication Required The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/tmp/test.py", line 3, in <module> pm.urlopen('GET', 'https://example.com') File "/tmp/venv/lib64/python3.10/site-packages/urllib3/poolmanager.py", line 634, in urlopen return super().urlopen(method, url, redirect=redirect, **kw) File "/tmp/venv/lib64/python3.10/site-packages/urllib3/poolmanager.py", line 444, in urlopen response = conn.urlopen(method, u.request_uri, **kw) File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( File "/tmp/venv/lib64/python3.10/site-packages/urllib3/util/retry.py", line 445, in increm ... (truncated) ...
Stack trace
error.txt
Error Message ------------- $ python3.10 -Werror test.py Traceback (most recent call last): File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connectionpool.py", line 779, in urlopen self._prepare_proxy(conn) File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connectionpool.py", line 1048, in _prepare_proxy conn.connect() File "/tmp/venv/lib64/python3.10/site-packages/urllib3/connection.py", line 633, in connect self._tunnel() # type: ignore[attr-defined] File "/usr/lib64/python3.10/http/client.py", line 925, in _tunnel raise OSError(f"Tunnel connection failed: {code} {message.strip()}") OSError: Tunnel connection failed: 407 Proxy Authentication Required The above exception was the direct cause of the following exception: urllib3.exceptions.ProxyError: ('Unable to connect to proxy', OSError('Tunnel connection failed: 407 Proxy Authentication Required')) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/tmp/test.py", line 3, in <module> pm.urlopen('GET', 'https://example.com') File "/tmp/venv/lib64/python3.10/site-packages/urllib3/poolmanager.py", line 634, in urlopen return super().urlopen(method, url, redirect=redirect, **kw) File "/tmp/venv/lib64/python3.10/site-packages/urllib3/poolmanager.py", line 444, in urlopen response = conn.urlopen(method, u.request_uri, **kw) File "/tmp/venv/ ... (truncated) ...

Minimal Reproduction

repro.py
from http.server import BaseHTTPRequestHandler from socketserver import ThreadingTCPServer class HTTPConnectProxyHandler(BaseHTTPRequestHandler): protocol_version = 'HTTP/1.1' default_request_version = 'HTTP/1.1' def do_CONNECT(self): self.send_response(407) self.send_header('Proxy-Authenticate', 'Basic') self.end_headers() ThreadingTCPServer(('127.0.0.1', 55556), HTTPConnectProxyHandler).serve_forever()

Environment

  • Python: 3.10
  • urllib3: 2.2.1

What Broke

CI fails due to unclosed socket warnings when receiving a 407 response from an HTTP proxy.

Why It Broke

ResourceWarnings were not properly handled for HTTP CONNECT responses with status 407 in urllib3

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install urllib3==1.26.20

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/urllib3/urllib3/pull/3252

First fixed release: 1.26.20

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use if it changes public behavior or if the failure cannot be reproduced.

Verify Fix

verify
Re-run: python3.10 -Werror test.py

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.
  • Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
  • Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.

Version Compatibility Table

VersionStatus
1.26.20 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.