# FastAPI 请求验证错误：路径参数 'item_id' 不是有效的整数

- **ID:** `python/fastapi-path-param-type-error`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

路径参数标注为 int，但 URL 中提供了非整数值。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Ensure the client sends an integer in the URL, e.g., /items/123
   ```
2. **** (100% 成功率)
   ```
   Use a Pydantic model or path converter: @app.get('/items/{item_id}') with item_id: int
   ```

## 无效尝试

- **** — This doesn't fix the client's request; they still need to send a valid integer. (60% 失败率)
- **** — Loses automatic validation; you have to handle conversion errors yourself. (50% 失败率)
