# aiohttp 客户端 HTTP 版本错误：无效的 HTTP 版本：HTTP/2

- **ID:** `python/aiohttp-client-connector-http-version-error`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |

## 解决方案

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

## 无效尝试

- **Disabling HTTP/2 support entirely** — Some servers require HTTP/2 for optimal performance or functionality. (40% 失败率)
- **Manually setting the HTTP version in headers** — The HTTP version is negotiated at the protocol level, not via headers. (60% 失败率)
