# fastapi.exceptions.RequestValidationError: [{'loc': ['body', 'age'], 'msg': '值不是有效的整数', 'type': 'type_error.integer'}]

- **ID:** `python/fastapi-body-validation-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求体中的字段类型验证失败，例如在需要整数的地方提供了字符串。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Ensure the client sends valid data types: age: 25 instead of age: "twenty-five".
   ```
2. **** (85% 成功率)
   ```
   Add custom validation logic or use Pydantic's Field constraints to give better error messages.
   ```

## 无效尝试

- **** — It doesn't help the client correct the input; the error persists. (80% 失败率)
- **** — This bypasses validation and can lead to runtime errors when processing the data. (60% 失败率)
