Jump to solution
Verify

The Fix

pip install urllib3==1.26.4

Based on closed urllib3/urllib3 issue #2126 · 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
@@ -232,14 +232,13 @@ you could connect to a server by IP using HTTPS like so:: >>> import urllib3 >>> pool = urllib3.HTTPSConnectionPool( - ... "10.0.0.10", - ... assert_hostname="example.org", - ... server_hostname="example.org"
repro.py
import urllib3 manager = urllib3.PoolManager(assert_hostname=True) r = manager.request('GET', 'https://google.com/') print(r.status)
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install urllib3==1.26.4\nWhen NOT to use: This fix is not applicable if the hostname validation is intentionally bypassed.\n\n

Why This Fix Works in Production

  • Trigger: chunked=chunked,
  • Mechanism: HTTPSConnection fails to validate hostnames when assert_hostname is set to True
  • Why the fix works: Improves documentation for `assert_hostname` and clarifies its usage in HTTPS connections. (first fixed release: 1.26.4).
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.6.12 in real deployments (not just unit tests).
  • HTTPSConnection fails to validate hostnames when assert_hostname is set to True
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

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

Discussion

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

“As said in the PR: we currently accept False, None and an actual hostname. We could document assert_hostname as an Optional[str], but would still have…”
@pquentin · 2021-02-23 · source

Failure Signature (Search String)

  • chunked=chunked,

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "<redacted>/lib/python3.6/site-packages/urllib3/connectionpool.py", line 677, in urlopen chunked=chunked, File "<redacted>/lib/python3.6/site-packages/urllib3/connectionpool.py", line 381, in _make_request self._validate_conn(conn) File "<redacted>/lib/python3.6/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn conn.connect() File "<redacted>/lib/python3.6/site-packages/urllib3/connection.py", line 397, in connect _match_hostname(cert, self.assert_hostname or server_hostname) File "<redacted>/lib/python3.6/site-packages/urllib3/connection.py", line 407, in _match_hostname match_hostname(cert, asserted_hostname) File "<redacted>/lib/python3.6/ssl.py", line 327, in match_hostname % (hostname, ', '.join(map(repr, dnsnames)))) ssl.CertificateError: hostname True doesn't match either of '*.google.com', '*.android.com', '*.appengine.google.com', '*.bdn.dev', '*.cloud.google.com', '*.crowdsource.google.com', '*.datacompute.google.com', '*.g.co', '*.gcp.gvt2.com', '*.gcpcdn.gvt1.com', '*.ggpht.cn', '*.gkecnapps.cn', '*.google-analytics.com', '*.google.ca', '*.google.cl', '*.google.co.in', '*.google.co.jp', '*.google.co.uk', '*.google.com.ar', '*.google.com.au', '*.google.com.br', '*.google.com.co', '*.google.com.mx', '*.google.com.tr', '*.google.com.vn', '*.google.de', '*.google.es', '*.goog ... (truncated) ...

Minimal Reproduction

repro.py
import urllib3 manager = urllib3.PoolManager(assert_hostname=True) r = manager.request('GET', 'https://google.com/') print(r.status)

Environment

  • Python: 3.6.12
  • urllib3: 1.25.11

What Broke

Users experience SSL certificate errors when connecting to HTTPS servers.

Why It Broke

HTTPSConnection fails to validate hostnames when assert_hostname is set to True

Fix Options (Details)

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

pip install urllib3==1.26.4

When NOT to use: This fix is not applicable if the hostname validation is intentionally bypassed.

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/2169

First fixed release: 1.26.4

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

  • This fix is not applicable if the hostname validation is intentionally bypassed.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

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.4 Fixed

Related Issues

No related fixes found.

Sources

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