python
runtime_error
ai_generated
true
starlette.exceptions.HTTPException: 405: Method Not Allowed
ID: python/starlette-http-exception-405-method-not-allowed
80%Fix Rate
83%Confidence
0Evidence
2024-06-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The HTTP method used (e.g., POST) is not allowed for the requested endpoint.
generic中文
使用的 HTTP 方法(例如 POST)不允许用于请求的端点。
Workarounds
-
90% success Define route with correct methods
from starlette.routing import Route async def handle(request): return PlainTextResponse('OK') app.add_route('/data', handle, methods=['POST']) -
95% success Use method-specific decorators
@app.post('/data') async def create(request): return JSONResponse({'status': 'created'})
Dead Ends
Common approaches that don't work:
-
Assuming all methods are allowed by default
80% fail
Starlette requires explicit method registration.
-
Using GET when POST is required
70% fail
Method mismatch leads to 405.