# aiohttp客户端异常：尝试用意外MIME类型解码JSON: text/html

- **ID:** `python/aiohttp-content-type-error`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在具有非JSON内容类型的响应上调用resp.json()。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   if resp.content_type == 'application/json': data = await resp.json() else: text = await resp.text()
   ```
2. **** (90% 成功率)
   ```
   data = await resp.json(content_type=None)
   ```

## 无效尝试

- **** — It's a client-side parameter, not a server-side fix. (70% 失败率)
- **** — Works but bypasses aiohttp's built-in error handling. (20% 失败率)
