The Fix
Upgrade to version 0.20.1 or later.
Based on closed Kludex/starlette issue #1619 · PR/commit linked
@@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
+import sys
from typing import Optional
Option A — Upgrade to fixed release\nUpgrade to version 0.20.1 or later.\nWhen NOT to use: Do not use this fix if Brotli is required for your application.\n\n
Why This Fix Works in Production
- Trigger: Test failures if `Brotli` is installed
- Mechanism: Brotli or brotlicffi causes mismatched accept-encoding in urllib3, leading to test failures
- Why the fix works: Skip tests when Brotli is installed to prevent failures due to mismatched accept-encoding headers. (first fixed release: 0.20.1).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.10.4 in real deployments (not just unit tests).
- Brotli or brotlicffi causes mismatched accept-encoding in urllib3, leading to test failures
- Production symptom (often without a traceback): Test failures if `Brotli` is installed
Proof / Evidence
- GitHub issue: #1619
- Fix PR: https://github.com/kludex/starlette/pull/1620
- First fixed release: 0.20.1
- 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.78
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“### Discussed in https://github.com/encode/starlette/discussions/1618 <div type='discussions-op-text'> <sup>Originally posted by **mgorny** May 3, 2022</sup> If Brotli or brotlicffi is installed on the system, urllib3 includes it in its acc”
Failure Signature (Search String)
- Test failures if `Brotli` is installed
- If `Brotli` or `brotlicffi` is installed on the system, urllib3 includes it in its `accept-encoding`. This causes starlette's tests to fail on mismatched `accept-encoding`.
Copy-friendly signature
Failure Signature
-----------------
Test failures if `Brotli` is installed
If `Brotli` or `brotlicffi` is installed on the system, urllib3 includes it in its `accept-encoding`. This causes starlette's tests to fail on mismatched `accept-encoding`.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Test failures if `Brotli` is installed
If `Brotli` or `brotlicffi` is installed on the system, urllib3 includes it in its `accept-encoding`. This causes starlette's tests to fail on mismatched `accept-encoding`.
Environment
- Python: 3.10.4
What Broke
Tests fail due to unexpected 'accept-encoding' headers when Brotli is installed.
Why It Broke
Brotli or brotlicffi causes mismatched accept-encoding in urllib3, leading to test failures
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.20.1 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/kludex/starlette/pull/1620
First fixed release: 0.20.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if Brotli is required for your application.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.20.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.