# AttributeError: 'Request' 对象没有属性 'json'

- **ID:** `python/fastapi-attributeerror-starlette-request-json`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在异步处理程序中使用 request.json 而不是 await request.json()。

## 版本兼容性

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

## 解决方案

1. **Use await request.json()** (95% 成功率)
   ```
   @app.post('/data')
async def handle(request):
    data = await request.json()
    return {'received': data}
   ```
2. **Use FastAPI's Body dependency** (90% 成功率)
   ```
   from fastapi import Body
@app.post('/data')
async def handle(data: dict = Body(...)):
    return {'received': data}
   ```

## 无效尝试

- **Using request.body() without await** — Similar issue: body is a coroutine. (70% 失败率)
- **Importing json module and parsing manually** — Overcomplicates; Starlette provides built-in method. (50% 失败率)
