{"id":"1175ad5703df7ade","repo":"aio-libs/aiohttp","slug":"can-not-decode-content-encoding-zstandard-zstd","errorCode":null,"errorMessage":"Can not decode content-encoding: zstandard (zstd). Please install `backports.zstd`","messagePattern":"Can not decode content-encoding: zstandard \\(zstd\\)\\. Please install `backports\\.zstd`","errorType":"exception","errorClass":"ContentEncodingError","httpStatus":400,"severity":"error","filePath":"aiohttp/http_parser.py","lineNumber":1145,"sourceCode":"        max_decompress_size: int = DEFAULT_CHUNK_SIZE,\n    ) -> None:\n        self.out = out\n        self.size = 0\n        out.total_compressed_bytes = self.size\n        self.encoding = encoding\n        self._started_decoding = False\n\n        self.decompressor: BrotliDecompressor | ZLibDecompressor | ZSTDDecompressor\n        if encoding == \"br\":\n            if not HAS_BROTLI:\n                raise ContentEncodingError(\n                    \"Can not decode content-encoding: brotli (br). \"\n                    \"Please install `Brotli`\"\n                )\n            self.decompressor = BrotliDecompressor()\n        elif encoding == \"zstd\":\n            if not HAS_ZSTD:\n                raise ContentEncodingError(\n                    \"Can not decode content-encoding: zstandard (zstd). \"\n                    \"Please install `backports.zstd`\"\n                )\n            self.decompressor = ZSTDDecompressor()\n        else:\n            self.decompressor = ZLibDecompressor(encoding=encoding)\n\n        self._max_decompress_size = max_decompress_size\n\n    def set_exception(\n        self,\n        exc: type[BaseException] | BaseException,\n        exc_cause: BaseException = _EXC_SENTINEL,\n    ) -> None:\n        set_exception(self.out, exc, exc_cause)\n\n    def feed_data(self, chunk: bytes) -> bool:\n        \"\"\"Return True if more data is available and this method should be called again with b\"\".\"\"\"","sourceCodeStart":1127,"sourceCodeEnd":1163,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/http_parser.py#L1127-L1163","documentation":"ContentEncodingError raised when a response advertises Content-Encoding: zstd (zstandard) but the zstandard/backports.zstd dependency is not installed (HAS_ZSTD is False). The body cannot be decompressed.","triggerScenarios":"Server responds with Content-Encoding: zstd and the runtime lacks the zstandard package (or backports.zstd on older Python). DeflateBuffer raises at construction time.","commonSituations":"New zstd adoption by a CDN/server; deploy image without zstandard; older Python needing backports.zstd; optional deps not installed.","solutions":["Install zstandard: `pip install zstandard` (or backports.zstd on supported versions).","Remove zstd from your Accept-Encoding if you cannot install the dep.","Use auto_decompress=False to receive raw compressed bytes."],"exampleFix":"// before\n#   server sends Content-Encoding: zstd, zstandard not installed\n\n# after\n#   pip install zstandard\n# or restrict Accept-Encoding:\nheaders = {'Accept-Encoding': 'gzip, deflate, br'}\nresp = await session.get(url, headers=headers)","handlingStrategy":"fallback","validationCode":"try:\n    import zstandard  # noqa\n    HAS_ZSTD = True\nexcept ImportError:\n    HAS_ZSTD = False\n\nasync def safe_get(session, url):\n    headers = {} if HAS_ZSTD else {'Accept-Encoding': 'gzip, deflate, br'}\n    return await session.get(url, headers=headers)","typeGuard":null,"tryCatchPattern":"from aiohttp.http_exceptions import ContentEncodingError\ntry:\n    body = await resp.read()\nexcept ContentEncodingError as e:\n    if 'zstd' in str(e):\n        # retry without zstd\n        ...","preventionTips":["Install zstandard when advertising zstd.","Constrain Accept-Encoding to encodings you can decode."],"tags":["http","compression","zstandard","zstd","dependency","response"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}