python
network_error
ai_generated
true
aiohttp.client_exceptions.ClientHttpVersionError: Invalid HTTP version: HTTP/2
ID: python/aiohttp-client-connector-http-version-error
80%Fix Rate
82%Confidence
0Evidence
2025-09-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 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
-
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: -
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:
-
Disabling HTTP/2 support entirely
40% fail
Some servers require HTTP/2 for optimal performance or functionality.
-
Manually setting the HTTP version in headers
60% fail
The HTTP version is negotiated at the protocol level, not via headers.