Skip to content

Can not decode content-encoding: zstd #11635

@seriaati

Description

@seriaati

Describe the bug

If you have aiohttp 3.13.0 and zstandard installed, exception "Can not decode content-encoding: zstd" is raised.

To Reproduce

pip install aiohttp
pip install zstandard
import asyncio
import aiohttp


async def main() -> None:
    async with aiohttp.ClientSession() as session:
        async with session.get("https://hoyo-codes.seria.moe/codes?game=genshin") as resp:
            await resp.json()


asyncio.run(main())

Expected behavior

JSON is parsed correctly without errors.

Logs/tracebacks

c:/Users/Seria/Documents/GitHub/hoyo-buddy/test.py
Traceback (most recent call last):
  File "C:\Users\Seria\Documents\GitHub\hoyo-buddy\.venv\Lib\site-packages\aiohttp\http_parser.py", line 1018, in feed_data      
    chunk = self.decompressor.decompress_sync(chunk)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Seria\Documents\GitHub\hoyo-buddy\.venv\Lib\site-packages\aiohttp\compression_utils.py", line 306, in decompress_sync
    return self._obj.decompress(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
zstandard.backend_c.ZstdError: could not determine content size in frame header

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "aiohttp/_http_parser.pyx", line 761, in aiohttp._http_parser.cb_on_body
    pyparser._payload.feed_data(body, length)
  File "C:\Users\Seria\Documents\GitHub\hoyo-buddy\.venv\Lib\site-packages\aiohttp\http_parser.py", line 1020, in feed_data      
    raise ContentEncodingError(
aiohttp.http_exceptions.ContentEncodingError: 400, message:
  Can not decode content-encoding: zstd

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\Seria\Documents\GitHub\hoyo-buddy\test.py", line 11, in <module>
    asyncio.run(main())
  File "C:\Users\Seria\AppData\Roaming\uv\python\cpython-3.12.10-windows-x86_64-none\Lib\asyncio\runners.py", line 195, in run   
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Seria\AppData\Roaming\uv\python\cpython-3.12.10-windows-x86_64-none\Lib\asyncio\runners.py", line 118, in run   
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Seria\AppData\Roaming\uv\python\cpython-3.12.10-windows-x86_64-none\Lib\asyncio\base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "c:\Users\Seria\Documents\GitHub\hoyo-buddy\test.py", line 8, in main
    await resp.json()
  File "C:\Users\Seria\Documents\GitHub\hoyo-buddy\.venv\Lib\site-packages\aiohttp\client_reqrep.py", line 753, in json
    await self.read()
  File "C:\Users\Seria\Documents\GitHub\hoyo-buddy\.venv\Lib\site-packages\aiohttp\client_reqrep.py", line 695, in read
    self._body = await self.content.read()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Seria\Documents\GitHub\hoyo-buddy\.venv\Lib\site-packages\aiohttp\streams.py", line 400, in read
    raise self._exception
aiohttp.client_exceptions.ClientPayloadError: 400, message:
  Can not decode content-encoding: zstd

Python Version

3.12.10

aiohttp Version

3.13.0

multidict Version

6.7.0

propcache Version

0.4.1

yarl Version

1.22.0

OS

Ubuntu

Related component

Client, Server Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions