The Fix
Upgrade to version 0.13.0 or later.
Based on closed encode/httpx issue #756 · PR/commit linked
Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.
@@ -45,12 +45,18 @@ class DeflateDecoder(Decoder):
def __init__(self) -> None:
- self.decompressor = zlib.decompressobj(-zlib.MAX_WBITS)
+ self.first_attempt = True
+ self.decompressor = zlib.decompressobj()
import zlib
def app(environ, start_response):
start_response("200 OK", [("Content-Encoding", "deflate")])
return [zlib.compress(b"hello world")]
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.13.0 or later.\nWhen NOT to use: This fix should not be used if the response encoding is guaranteed to be strictly 'deflate'.\n\n
Why This Fix Works in Production
- Trigger: >> httpx.get('http://localhost:9999')
- Mechanism: The DeflateDecoder was using a fixed zlib decompression method that failed for certain compressed responses
- Why the fix works: Adds support for both zlib and deflate encodings in the DeflateDecoder, addressing the DecodingError issue. (first fixed release: 0.13.0).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- The DeflateDecoder was using a fixed zlib decompression method that failed for certain compressed responses
- Surfaces as: >> httpx.get('http://localhost:9999')
Proof / Evidence
- GitHub issue: #756
- Fix PR: https://github.com/encode/httpx/pull/758
- First fixed release: 0.13.0
- 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.42
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@tomchristie bit of a long story, but in short I'm trying to serve a file in chunks that's already been deflated and stored on disk”
“Heya! So, there's some useful context on this here..”
Failure Signature (Search String)
- >> httpx.get('http://localhost:9999')
Error Message
Stack trace
Error Message
-------------
>> httpx.get('http://localhost:9999')
Traceback (most recent call last):
File "/Users/jamie/code/httpx/httpx/decoders.py", line 52, in decode
return self.decompressor.decompress(data)
zlib.error: Error -3 while decompressing data: invalid stored block lengths
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jamie/code/httpx/httpx/api.py", line 170, in get
trust_env=trust_env,
File "/Users/jamie/code/httpx/httpx/api.py", line 96, in request
allow_redirects=allow_redirects,
File "/Users/jamie/code/httpx/httpx/client.py", line 568, in request
request, auth=auth, allow_redirects=allow_redirects, timeout=timeout,
File "/Users/jamie/code/httpx/httpx/client.py", line 593, in send
response.read()
File "/Users/jamie/code/httpx/httpx/models.py", line 900, in read
self._content = b"".join([part for part in self.iter_bytes()])
File "/Users/jamie/code/httpx/httpx/models.py", line 900, in <listcomp>
self._content = b"".join([part for part in self.iter_bytes()])
File "/Users/jamie/code/httpx/httpx/models.py", line 912, in iter_bytes
yield self.decoder.decode(chunk)
File "/Users/jamie/code/httpx/httpx/decoders.py", line 54, in decode
raise DecodingError from exc
httpx.exceptions.DecodingError
Minimal Reproduction
import zlib
def app(environ, start_response):
start_response("200 OK", [("Content-Encoding", "deflate")])
return [zlib.compress(b"hello world")]
What Broke
httpx raises a DecodingError when attempting to decode zlib-compressed responses.
Why It Broke
The DeflateDecoder was using a fixed zlib decompression method that failed for certain compressed responses
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.13.0 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/758
First fixed release: 0.13.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the response encoding is guaranteed to be strictly 'deflate'.
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.
- Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
- Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.13.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.