python
config_error
ai_generated
true
ValueError: 重复的路由路径:/items
ValueError: Duplicate route path: /items
ID: python/fastapi-valueerror-duplicate-route-path
80%修复率
86%置信度
0证据数
2024-05-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
两个路由装饰器定义了相同的路径而没有区分方法。
English
Two route decorators define the same path without differentiating methods.
解决方案
-
95% 成功率 Use different HTTP methods for same path
@app.get('/items') async def list_items(): pass @app.post('/items') async def create_item(): pass -
90% 成功率 Use different paths
@app.get('/items') async def list_items(): pass @app.get('/items/{item_id}') async def get_item(item_id: int): pass
无效尝试
常见但无效的做法:
-
Removing one route entirely
50% 失败
May lose needed functionality.
-
Changing function name only
70% 失败
Path remains duplicate.