Jump to solution
Verify

The Fix

pip install urllib3==2.2.1

Based on closed urllib3/urllib3 issue #3343 · 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 ``HTTPConnectionPool.urlopen`` to stop automatically casting non-proxy headers to ``HTTPHeaderDict``. This change was premature as it did not apply to proxy headers and ``HTTPHeaderDict`` does not handle byte header values correctly yet. diff --git a/src/urllib3/connectionpool.py b/src/urllib3/connectionpool.py index 1036f0d718..bd58ff14dd 100644
repro.py
from urllib3._collections import HTTPHeaderDict hdict = HTTPHeaderDict({'x-my-header': b'my-binary-value'}) # Any access that invokes `.get()` will fail (print, get, getall, etc.) print(hdict)
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==2.2.1\nWhen NOT to use: This fix should not be used if the application relies on the previous behavior of casting headers.\n\n

Why This Fix Works in Production

  • Trigger: >> print(hdict)
  • Mechanism: Stops automatically casting non-proxy headers to HTTPHeaderDict, addressing issues with byte header values.
  • Why the fix works: Stops automatically casting non-proxy headers to HTTPHeaderDict, addressing issues with byte header values. (first fixed release: 2.2.1).
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.11 in real deployments (not just unit tests).
  • Surfaces as: >> print(hdict)

Proof / Evidence

  • GitHub issue: #3343
  • Fix PR: https://github.com/urllib3/urllib3/pull/3344
  • First fixed release: 2.2.1
  • 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.46

Discussion

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

“There is already an existing ticket + PR to accept bytes values in the HTTPHeaderDict: https://github.com/urllib3/urllib3/issues/3072 https://github.com/urllib3/urllib3/pull/3279 Would be interesting to see if that PR…”
@bblommers · 2024-02-14 · source
“Thanks for the investigation! We need to review and merge #3279, but we should also consider if we really want to cast headers to HTTPHeaderDict.”
@pquentin · 2024-02-15 · source
“Thanks for pointing those out, @bblommers! Yeah, I agree those seem to be inline with this issue”
@nateprewitt · 2024-02-14 · source
“Adding some more context after further digging”
@nateprewitt · 2024-02-14 · source

Failure Signature (Search String)

  • >> print(hdict)

Error Message

Stack trace
error.txt
Error Message ------------- >> print(hdict) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/private/tmp/.venv/lib/python3.11/site-packages/urllib3/_collections.py", line 423, in __repr__ return f"{type(self).__name__}({dict(self.itermerged())})" ^^^^^^^^^^^^^^^^^^^^^^^ File "/private/tmp/.venv/lib/python3.11/site-packages/urllib3/_collections.py", line 446, in itermerged yield val[0], ", ".join(val[1:]) ^^^^^^^^^^^^^^^^^^

Minimal Reproduction

repro.py
from urllib3._collections import HTTPHeaderDict hdict = HTTPHeaderDict({'x-my-header': b'my-binary-value'}) # Any access that invokes `.get()` will fail (print, get, getall, etc.) print(hdict)

Environment

  • Python: 3.11
  • urllib3: 2.2

What Broke

Users experienced TypeErrors when accessing headers defined as bytes in HTTPHeaderDict.

Fix Options (Details)

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

pip install urllib3==2.2.1

When NOT to use: This fix should not be used if the application relies on the previous behavior of casting headers.

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

First fixed release: 2.2.1

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 should not be used if the application relies on the previous behavior of casting headers.

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.

Version Compatibility Table

VersionStatus
2.2.1 Fixed

Related Issues

No related fixes found.

Sources

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