python network_error ai_generated true

aiohttp.client_exceptions.ClientHttpVersionError: Invalid HTTP version: HTTP/2

ID: python/aiohttp-client-connector-http-version-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2025-09-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.10 active
3.11 active

Root Cause

The server uses HTTP/2, but aiohttp is configured to use HTTP/1.1 only, or vice versa.

generic

中文

服务器使用 HTTP/2,但 aiohttp 配置为仅使用 HTTP/1.1,反之亦然。

Workarounds

  1. 90% success Enable HTTP/2 support with aiohttp
    import aiohttp
    async with aiohttp.ClientSession(http2=True) as session:
        async with session.get(url) as resp:
  2. 85% success Use a custom connector with HTTP/2 enabled
    connector = aiohttp.TCPConnector(force_close=True, http2=True)
    async with aiohttp.ClientSession(connector=connector) as session:

Dead Ends

Common approaches that don't work:

  1. Disabling HTTP/2 support entirely 40% fail

    Some servers require HTTP/2 for optimal performance or functionality.

  2. Manually setting the HTTP version in headers 60% fail

    The HTTP version is negotiated at the protocol level, not via headers.