The Fix
Upgrade to version 0.15.4 or later.
Based on closed encode/httpx issue #1325 · PR/commit linked
@@ -724,9 +724,11 @@ def __len__(self) -> int:
def __eq__(self, other: typing.Any) -> bool:
- if not isinstance(other, Headers):
+ try:
+ other_headers = Headers(other)
def __eq__(self, other: typing.Any) -> bool:
try:
other_headers = Headers(other)
except ValueError:
return False
return sorted(self._list) == sorted(other_headers._list)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.15.4 or later.\nWhen NOT to use: This fix should not be used if strict type checking for headers is required.\n\n
Why This Fix Works in Production
- Trigger: assert response.status_code == 200
- Mechanism: The equality method for headers did not support comparisons with dicts or lists
- Why the fix works: Supports header comparisons with dicts or lists, allowing for simpler assertions in tests. (first fixed release: 0.15.4).
Why This Breaks in Prod
- The equality method for headers did not support comparisons with dicts or lists
- Production symptom (often without a traceback): assert response.status_code == 200
Proof / Evidence
- GitHub issue: #1325
- Fix PR: https://github.com/encode/httpx/pull/1326
- First fixed release: 0.15.4
- 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.68
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“We should support direct header comparisons with dicts, or with lists of two-tuples. This would be nice because it would help folks clean up test cases, eg... The fix will be something like changing Headers.__eq__ from this... To this... A”
Failure Signature (Search String)
- assert response.status_code == 200
- assert response.text == "Hello, world!"
Copy-friendly signature
Failure Signature
-----------------
assert response.status_code == 200
assert response.text == "Hello, world!"
Error Message
Signature-only (no traceback captured)
Error Message
-------------
assert response.status_code == 200
assert response.text == "Hello, world!"
Minimal Reproduction
def __eq__(self, other: typing.Any) -> bool:
try:
other_headers = Headers(other)
except ValueError:
return False
return sorted(self._list) == sorted(other_headers._list)
What Broke
Users faced issues when asserting header equality in tests, leading to false negatives.
Why It Broke
The equality method for headers did not support comparisons with dicts or lists
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.15.4 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/encode/httpx/pull/1326
First fixed release: 0.15.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if strict type checking for headers is required.
Verify Fix
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
| Version | Status |
|---|---|
| 0.15.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.