# fastapi.exceptions.HTTPException: 422 Unprocessable Entity

- **ID:** `python/fastapi-missing-content-type`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI请求体为JSON但缺少Content-Type头，导致验证失败。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **确保客户端发送正确的Content-Type头** (95% success)
   ```
   requests.post(url, json={'key': 'value'})  # 自动设置Content-Type: application/json
   ```
2. **使用中间件检查并设置默认Content-Type** (85% success)
   ```
   from starlette.middleware.base import BaseHTTPMiddleware; class ContentTypeMiddleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): if not request.headers.get('Content-Type'): request.headers.__dict__['_list'].append(('content-type', 'application/json')); return await call_next(request)
   ```

## Dead Ends

- **忽略Content-Type头，期望框架自动检测** — FastAPI严格依赖Content-Type头。 (90% fail)
- **在路由中使用request.json()手动解析** — 仍然需要Content-Type头。 (80% fail)
