{"record":{"id":"075aa86b9de1d880","repo":"aio-libs/aiohttp","slug":"unknown-content-encoding-encoding","errorCode":null,"errorMessage":"unknown content encoding: {encoding}","messagePattern":"unknown content encoding: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"aiohttp/multipart.py","lineNumber":580,"sourceCode":"        \"\"\"\n        data = self._apply_content_transfer_decoding(data)\n        if self._needs_content_decoding():\n            async for d in self._decode_content_async(data):\n                yield d\n        else:\n            yield data\n\n    def _decode_content(self, data: bytes) -> bytes:\n        encoding = self.headers.get(CONTENT_ENCODING, \"\").lower()\n        if encoding == \"identity\":\n            return data\n        if encoding in {\"deflate\", \"gzip\"}:\n            return ZLibDecompressor(\n                encoding=encoding,\n                suppress_deflate_header=True,\n            ).decompress_sync(data, max_length=self._max_decompress_size)\n\n        raise RuntimeError(f\"unknown content encoding: {encoding}\")\n\n    async def _decode_content_async(self, data: bytes) -> AsyncIterator[bytes]:\n        encoding = self.headers.get(CONTENT_ENCODING, \"\").lower()\n        if encoding == \"identity\":\n            yield data\n        elif encoding in {\"deflate\", \"gzip\"}:\n            d = ZLibDecompressor(\n                encoding=encoding,\n                suppress_deflate_header=True,\n            )\n            yield await d.decompress(data, max_length=self._max_decompress_size)\n            while d.data_available:\n                yield await d.decompress(b\"\", max_length=self._max_decompress_size)\n        else:\n            raise RuntimeError(f\"unknown content encoding: {encoding}\")\n\n    def _decode_content_transfer(self, data: bytes) -> bytes:\n        encoding = self.headers.get(CONTENT_TRANSFER_ENCODING, \"\").lower()","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/multipart.py#L562-L598","documentation":"Raised by the synchronous _decode_content when a body part's Content-Encoding header is neither 'identity' nor one of the supported 'deflate'/'gzip'. Only those three encodings are implemented via ZLibDecompressor.","triggerScenarios":"A part with Content-Encoding set to 'br', 'compress', 'zstd', 'x-gzip' (misspelled), or any other token; the sync decode path is hit when content is decoded in batch.","commonSituations":"A peer advertising modern encodings (Brotli/Zstandard) that aiohttp's multipart decoder does not handle; typos in Content-Encoding; custom encoding tokens.","solutions":["Restrict Content-Encoding on multipart parts to identity, deflate, or gzip.","If you need Brotli/Zstandard, pre-decode the bytes yourself before wrapping them in a part, or register a custom decode step.","Strip the unsupported Content-Encoding header and decompress externally.","Catch RuntimeError at the decode site and fall back to raw bytes."],"exampleFix":"// before\nContent-Encoding: br\n\n// after\nContent-Encoding: gzip","handlingStrategy":"validation","validationCode":"SUPPORTED_CONTENT_ENCODING = {'identity', 'deflate', 'gzip'}\n\ndef assert_supported_encoding(headers):\n    ce = headers.get('Content-Encoding', '').lower()\n    if ce and ce not in SUPPORTED_CONTENT_ENCODING:\n        raise ValueError(f'Unsupported Content-Encoding for sync decode: {ce}')","typeGuard":"def is_supported_content_encoding(value: object) -> bool:\n    return isinstance(value, str) and value.lower() in {'identity', 'deflate', 'gzip'}","tryCatchPattern":"try:\n    decoded = part._decode_content(data)\nexcept RuntimeError as e:\n    if 'unknown content encoding' in str(e):\n        decoded = data  # or hand off to a custom decoder\n    else:\n        raise","preventionTips":["Restrict part-level Content-Encoding to identity/deflate/gzip.","Pre-decode unsupported encodings (br/zstd) before constructing the part.","Validate headers before forwarding or parsing."],"tags":["multipart","content-encoding","compression","decoding"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}