# starlette.exceptions.HTTPException: 405: Method Not Allowed

- **ID:** `python/starlette-http-exception-405-method-not-allowed`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The HTTP method used (e.g., POST) is not allowed for the requested endpoint.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Define route with correct methods** (90% success)
   ```
   from starlette.routing import Route
async def handle(request):
    return PlainTextResponse('OK')
app.add_route('/data', handle, methods=['POST'])
   ```
2. **Use method-specific decorators** (95% success)
   ```
   @app.post('/data')
async def create(request):
    return JSONResponse({'status': 'created'})
   ```

## Dead Ends

- **Assuming all methods are allowed by default** — Starlette requires explicit method registration. (80% fail)
- **Using GET when POST is required** — Method mismatch leads to 405. (70% fail)
