python
config_error
ai_generated
true
ValueError: Duplicate route path: /items
ID: python/fastapi-valueerror-duplicate-route-path
80%Fix Rate
86%Confidence
0Evidence
2024-05-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Two route decorators define the same path without differentiating methods.
generic中文
两个路由装饰器定义了相同的路径而没有区分方法。
Workarounds
-
95% success Use different HTTP methods for same path
@app.get('/items') async def list_items(): pass @app.post('/items') async def create_item(): pass -
90% success Use different paths
@app.get('/items') async def list_items(): pass @app.get('/items/{item_id}') async def get_item(item_id: int): pass
Dead Ends
Common approaches that don't work:
-
Removing one route entirely
50% fail
May lose needed functionality.
-
Changing function name only
70% fail
Path remains duplicate.