python
data_error
ai_generated
true
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html'
ID: python/aiohttp-content-type-error
80%Fix Rate
85%Confidence
0Evidence
2025-05-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
Root Cause
Calling resp.json() on a response with a non-JSON content type.
generic中文
在具有非JSON内容类型的响应上调用resp.json()。
Workarounds
-
95% success
if resp.content_type == 'application/json': data = await resp.json() else: text = await resp.text()
-
90% success
data = await resp.json(content_type=None)
Dead Ends
Common approaches that don't work:
-
70% fail
It's a client-side parameter, not a server-side fix.
-
20% fail
Works but bypasses aiohttp's built-in error handling.