# aiohttp.client_exceptions.ServerDisconnectedError: 服务器断开连接

- **ID:** `python/aiohttp-server-disconnected`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

远程服务器在发送完整响应之前关闭了 TCP 连接，通常是由于 keep-alive 超时、服务器端崩溃或代理干扰。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   Enable retries with exponential backoff using aiohttp's built-in retry or a custom decorator:

from aiohttp_retry import RetryClient, ExponentialRetry
retry_options = ExponentialRetry(attempts=3)
async with RetryClient(retry_options=retry_options) as client:
    await client.get(url)
   ```
2. **** (70% 成功率)
   ```
   Set a Connection: close header to avoid keep-alive reuse:

headers = {'Connection': 'close'}
async with session.get(url, headers=headers) as resp:
    ...
   ```

## 无效尝试

- **** — The disconnect is not caused by slowness; a longer timeout just delays the failure. (60% 失败率)
- **** — The error is at the TCP layer, not TLS; disabling SSL does not prevent the server from closing the connection. (80% 失败率)
