python
data_error
ai_generated
true
werkzeug.exceptions.UnsupportedMediaType: 415 Unsupported Media Type: Did not attempt to load JSON data because the request Content-Type was not 'application/json'.
ID: python/flask-json-415-unsupported-media-type
80%Fix Rate
85%Confidence
0Evidence
2024-09-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
| 3.x | active | — | — | — |
Root Cause
request.get_json() called but the client sent no Content-Type: application/json header (common with curl or fetch defaults).
generic中文
调用了 request.get_json(),但客户端未发送 Content-Type: application/json 头(常见于 curl 或 fetch 默认行为)。
Workarounds
-
95% success
curl -X POST -H 'Content-Type: application/json' -d '{"a":1}' http://localhost:5000/api -
88% success
data = request.get_json(silent=True) or {} # explicit fallback for non-JSON
Dead Ends
Common approaches that don't work:
-
55% fail
Hides the contract bug and can produce confusing 400s on malformed bodies.
-
70% fail
Returns wrong status; client still gets no data.