aio-libs/aiohttp · error · ContentEncodingError
deflate
Error message
deflate
What it means
ContentEncodingError('deflate') raised in DeflateBuffer.feed_eof when, after consuming all input for a deflate-encoded body, the zlib decompressor reports it has not reached end-of-stream (decompressor.eof is False). This indicates the deflate stream is incomplete/truncated.
Source
Thrown at aiohttp/http_parser.py:1207
raise ContentEncodingError(
"Can not decode content-encoding: %s" % self.encoding
)
if chunk:
self.out.feed_data(chunk)
return self.decompressor.data_available
def feed_eof(self) -> None:
chunk = self.decompressor.flush()
# This should never contain data as we defer the call until exhausting
# the decompression. If .flush() is returning data, this may indicate a
# zip bomb vulnerability as it will decompress all remaining data at once.
assert not chunk
if self.size > 0:
# decompressor is not brotli unless encoding is "br"
if self.encoding == "deflate" and not self.decompressor.eof: # type: ignore[union-attr]
raise ContentEncodingError("deflate")
self.out.feed_eof()
def begin_http_chunk_receiving(self) -> None:
self.out.begin_http_chunk_receiving()
def end_http_chunk_receiving(self) -> None:
self.out.end_http_chunk_receiving()
HttpRequestParserPy = HttpRequestParser
HttpResponseParserPy = HttpResponseParser
RawRequestMessagePy = RawRequestMessage
RawResponseMessagePy = RawResponseMessage
with suppress(ImportError):
if not NO_EXTENSIONS:
from ._http_parser import ( # type: ignore[import-not-found,no-redef]View on GitHub (pinned to c0ef574e29)
Solutions
- Confirm the full deflate stream was delivered (compare against curl --compressed).
- Check for truncation by the server/proxy.
- Retry; handle as a transport error.
- Use Accept-Encoding: identity to bypass if upstream is consistently broken.
Defensive patterns
Strategy: fallback
Try / catch
from aiohttp.http_exceptions import ContentEncodingError
try:
body = await resp.read()
except ContentEncodingError:
# truncated deflate — retry or request identity
... Prevention
- Treat incomplete deflate as truncation.
- Stream reads to detect truncation earlier.
When it happens
Trigger: On EOF for a deflate body, if size > 0 and `not self.decompressor.eof`, the stream didn't finish cleanly — truncated deflate payload. feed_eof raises ContentEncodingError('deflate').
Common situations: Truncated gzip/deflate download; server closing the connection before flushing the final deflate block; proxy truncation; miscomputed Content-Length on a compressed body.
Related errors
- Can not decode content-encoding: brotli (br). Please install
- Can not decode content-encoding: zstandard (zstd). Please in
- Can not decode content-encoding: %s
- Invalid window size
- Extension for deflate not supported{ext}
AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04).
Data as JSON: /data/errors/4b5f1fc1ef80dc88.json.
Report an issue: GitHub.