# 值错误: 重复的路径操作: GET /items/{item_id}

- **ID:** `python/fastapi-path-operation-conflict`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

FastAPI中定义了多个相同HTTP方法和路径的路由。

## 版本兼容性

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

## 解决方案

1. **确保每个路径和方法组合唯一** (95% 成功率)
   ```
   @app.get('/items/{item_id}') async def read_item(item_id: int): return {'item_id': item_id}; @app.post('/items/{item_id}') async def update_item(item_id: int): return {'updated': item_id}
   ```
2. **使用不同的路径或添加版本前缀** (90% 成功率)
   ```
   @app.get('/v1/items/{item_id}') async def read_item_v1(item_id: int): return {'item_id': item_id}
   ```

## 无效尝试

- **尝试覆盖路由而不删除旧路由** — FastAPI不允许重复注册。 (90% 失败率)
- **使用不同的函数名但相同的路径和方法** — 路径和方法是唯一标识。 (80% 失败率)
