python
data_error
ai_generated
true
aiohttp客户端异常:尝试用意外MIME类型解码JSON: text/html
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html'
ID: python/aiohttp-content-type-error
80%修复率
85%置信度
0证据数
2025-05-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
根因分析
在具有非JSON内容类型的响应上调用resp.json()。
English
Calling resp.json() on a response with a non-JSON content type.
解决方案
-
95% 成功率
if resp.content_type == 'application/json': data = await resp.json() else: text = await resp.text()
-
90% 成功率
data = await resp.json(content_type=None)
无效尝试
常见但无效的做法:
-
70% 失败
It's a client-side parameter, not a server-side fix.
-
20% 失败
Works but bypasses aiohttp's built-in error handling.