python runtime_error ai_generated true

werkzeug.exceptions.MethodNotAllowed: 405 Method Not Allowed: The method is not allowed for the requested URL.

ID: python/flask-405-method-not-allowed

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-04-09First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

The route is registered for a different HTTP method (e.g. only GET) while the client sends POST/PUT/DELETE.

generic

中文

路由注册的 HTTP 方法与客户端发送的方法不一致(例如只注册了 GET 而客户端发送 POST/PUT/DELETE)。

Workarounds

  1. 96% success
    @app.route('/submit', methods=['GET', 'POST'])
    def submit(): ...
  2. 90% success
    @app.post('/submit')
    def submit_post(): ...

Dead Ends

Common approaches that don't work:

  1. 85% fail

    CSRF produces 400/403, not 405; the route method list is the actual cause.

  2. 80% fail

    Masks the real routing mismatch and breaks clients.