flask
Flask / Werkzeug Exceptions
HTTP exception classes from werkzeug.exceptions, the module Flask uses internally for aborting requests and generating error responses. Raised directly, via Flask's abort(), or automatically by Werkzeug's routing, request-parsing, and file-upload handling.
21 codes
references werkzeug.palletsprojects.com/en/stable/exceptions/flask.palletsprojects.com/en/stable/errorhandling/
· All codes 21 codes
- BadGateway BadGateway The 502 response raised by abort(502) when a Flask app acting as a gateway or proxy receives an invalid response from an upstream server it depends on.
- BadRequest BadRequest The 400 response raised by abort(400) or automatically when Werkzeug fails to parse the incoming request, e.g. request.get_json() hitting malformed JSON, a form body that can't be decoded, or a routing converter rejecting a URL segment.
- Conflict Conflict The 409 response raised by abort(409) when the request conflicts with the current state of the target resource, such as attempting to create a record that already exists.
- Forbidden Forbidden The 403 response raised by abort(403) when the client is authenticated but not permitted to access the resource, such as a failed permission check inside a view function.
- GatewayTimeout GatewayTimeout The 504 response raised by abort(504) when a Flask app acting as a gateway didn't receive a timely response from an upstream server it was waiting on.
- Gone Gone The 410 response raised by abort(410) to indicate the requested resource used to exist but has been permanently removed, as opposed to NotFound which makes no claim about whether it ever existed.
- ImATeapot ImATeapot The 418 response defined by the April Fools' HTCPCP RFC 2324. Werkzeug implements it purely as an easter egg exception; abort(418) is sometimes used in Flask apps for jokes or as a deliberately unmistakable test response.
- InternalServerError InternalServerError The 500 response Flask returns when a view function raises an unhandled exception outside of debug mode. In debug mode this is replaced by the interactive Werkzeug debugger traceback instead of a plain error page.
- LengthRequired LengthRequired The 411 response raised when a request that requires a Content-Length header is missing one, most often seen with chunked-transfer clients hitting a view that needs to know the body size up front.
- MethodNotAllowed MethodNotAllowed The 405 response raised automatically when a URL rule matches but the request's HTTP method isn't in the route's declared methods list, e.g. sending POST to a view only registered for GET. The response includes an Allow header listing the valid methods.
- NotAcceptable NotAcceptable The 406 response raised when the server can't produce a response matching the Accept header sent by the client. Rare in default Flask apps; typically only raised by extensions that do explicit content negotiation.
- NotFound NotFound The 404 response raised by abort(404), or automatically by Werkzeug's URL routing when no rule matches the request path. The most commonly seen error handler in Flask apps, registered with @app.errorhandler(404).
- NotImplemented NotImplemented The 501 response raised by abort(501) to indicate the server doesn't support the functionality required to fulfill the request, such as an HTTP method the application has no handling logic for at all.
- PreconditionFailed PreconditionFailed The 412 response raised when a conditional request's If-Match, If-None-Match, or If-Unmodified-Since header fails to match the current state of the resource on the server.
- RequestEntityTooLarge RequestEntityTooLarge The 413 response raised automatically when the request body exceeds the app's MAX_CONTENT_LENGTH (or per-part MAX_FORM_MEMORY_SIZE/MAX_CONTENT_LENGTH in Flask 3.1+) configuration, commonly hit on large file uploads.
- RequestTimeout RequestTimeout The 408 response indicating the client took too long to send the request. In practice this is usually raised by the WSGI server (e.g. gunicorn's --timeout) rather than Flask application code itself.
- ServiceUnavailable ServiceUnavailable The 503 response raised by abort(503), typically returned when the application is intentionally down for maintenance or a dependency (like a database connection pool) is temporarily exhausted.
- TooManyRequests TooManyRequests The 429 response raised by rate-limiting extensions such as Flask-Limiter once a client exceeds its configured request quota. Can carry a Retry-After header telling the client when to try again.
- Unauthorized Unauthorized The 401 response raised by abort(401) when a request lacks valid authentication credentials. Flask-Login and other auth extensions raise this from their login-required decorators before a view function runs.
- UnprocessableEntity UnprocessableEntity The 422 response raised when the request is well-formed but semantically invalid. Flask-RESTful, Flask-SQLAlchemy, and form/schema validation libraries commonly raise this for failed input validation instead of a generic 400.
- UnsupportedMediaType UnsupportedMediaType The 415 response raised by request.get_json() when the request's Content-Type isn't application/json (or a variant), unless called with force=True. A frequent cause of unexpected errors on API endpoints hit without a JSON content type.