Jump to solution
Details

The Fix

pip install urllib3==1.25.4

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

Open PR/Commit
@@ -429,7 +429,7 @@ def _match_hostname(cert, asserted_hostname): match_hostname(cert, asserted_hostname) except CertificateError as e: - log.error( + log.warning( "Certificate did not match expected hostname: %s. " "Certificate: %s",
fix.md
Option A — Upgrade to fixed release\npip install urllib3==1.25.4\nWhen NOT to use: This fix is not suitable if the application requires strict error logging for all certificate issues.\n\n

Why This Fix Works in Production

  • Trigger: urllib3 should not log an error on certificate mismatch
  • Mechanism: The logging level for CertificateError was set to error instead of warning, causing unnecessary log noise
  • Why the fix works: Changed the log level of CertificateError from error to warning within the match_hostname function to reduce unnecessary logging. (first fixed release: 1.25.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

  • The logging level for CertificateError was set to error instead of warning, causing unnecessary log noise
  • Production symptom (often without a traceback): urllib3 should not log an error on certificate mismatch

Proof / Evidence

  • GitHub issue: #1650
  • Fix PR: https://github.com/urllib3/urllib3/pull/1657
  • First fixed release: 1.25.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.71

Discussion

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

“I agree that logging this error is probably not necessary especially because we raise an exception right afterwards. Would be interesting to dig up the…”
@sethmlarson · 2019-07-08 · source
“Should we be doing more log.X() calls? Connections can fail in so many different areas, do you have an insight into why is this one…”
@sethmlarson · 2019-07-08 · source
“So the reality is that not everyone is using urllib3 directly and _peer_cert isn't always accessible to users”
@sigmavirus24 · 2019-07-08 · source
“So I think this was added by SurveyMonkey / @msabramo because they were trying to pin down which server in a group was serving an…”
@sigmavirus24 · 2019-07-08 · source

Failure Signature (Search String)

  • urllib3 should not log an error on certificate mismatch
  • Logging an error and then reraising the exception does not achieve much as the application code will have to handle the exception anyway. It's better to let the application decide
Copy-friendly signature
signature.txt
Failure Signature ----------------- urllib3 should not log an error on certificate mismatch Logging an error and then reraising the exception does not achieve much as the application code will have to handle the exception anyway. It's better to let the application decide if it's a noteworthy event or not.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- urllib3 should not log an error on certificate mismatch Logging an error and then reraising the exception does not achieve much as the application code will have to handle the exception anyway. It's better to let the application decide if it's a noteworthy event or not.

What Broke

Excessive error logging leads to cluttered logs and potential missed important messages.

Why It Broke

The logging level for CertificateError was set to error instead of warning, causing unnecessary log noise

Fix Options (Details)

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

pip install urllib3==1.25.4

When NOT to use: This fix is not suitable if the application requires strict error logging for all certificate issues.

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

First fixed release: 1.25.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 suitable if the application requires strict error logging for all certificate issues.

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

Related Issues

No related fixes found.

Sources

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