# aiohttp客户端异常：404，消息='未找到'，url=URL('http://example.com/nonexistent')

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

## 根因

服务器返回4xx或5xx状态码，如果调用raise_for_status，aiohttp会引发异常。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.7 | active | — | — |
| 3.8 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   if resp.status != 200: raise Exception(f'HTTP {resp.status}')
   ```
2. **** (90% 成功率)
   ```
   try: resp.raise_for_status() except aiohttp.ClientResponseError as e: print(e.status)
   ```

## 无效尝试

- **** — The error is raised by raise_for_status(); if you don't call it, no exception occurs. (60% 失败率)
- **** — The resource doesn't exist; changing method won't help. (80% 失败率)
