python
network_error
ai_generated
true
starlette.exceptions.HTTPException: 404 Not Found
ID: python/starlette-route-not-found
80%Fix Rate
84%Confidence
0Evidence
2024-07-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
请求的 URL 路径与任何已定义的路由都不匹配,或使用了错误的方法(如 GET 而非 POST)。
generic中文
请求的 URL 路径与任何已定义的路由都不匹配,或使用了错误的方法(如 GET 而非 POST)。
Workarounds
-
90% success
from starlette.routing import Route async def homepage(request): return Response('Hello') app = Starlette(routes=[Route('/', homepage)]) -
85% success
from starlette.routing import Route async def catch_all(request): return JSONResponse({'error': 'not found'}, status_code=404) app = Starlette(routes=[Route('/{path:path}', catch_all)])
Dead Ends
Common approaches that don't work:
-
50% fail
根路径可能也没有定义路由,仍然会得到 404。
-
80% fail
问题在于路由配置,忽略后无法访问目标资源。