# werkzeug.exceptions.UnsupportedMediaType: 415 不支持的媒体类型：请求 Content-Type 不是 'application/json'，未尝试加载 JSON 数据。

- **ID:** `python/flask-json-415-unsupported-media-type`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

调用了 request.get_json()，但客户端未发送 Content-Type: application/json 头（常见于 curl 或 fetch 默认行为）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   curl -X POST -H 'Content-Type: application/json' -d '{"a":1}' http://localhost:5000/api
   ```
2. **** (88% 成功率)
   ```
   data = request.get_json(silent=True) or {}  # explicit fallback for non-JSON
   ```

## 无效尝试

- **** — Hides the contract bug and can produce confusing 400s on malformed bodies. (55% 失败率)
- **** — Returns wrong status; client still gets no data. (70% 失败率)
