module documentation

Implements a number of Python exceptions which can be raised from within a view to trigger a standard HTTP non-200 response. Usage Example ------------- .. code-block:: python from werkzeug.wrappers.request import Request from werkzeug.exceptions import HTTPException, NotFound def view(request): raise NotFound() @Request.application def application(request): try: return view(request) except HTTPException as e: return e As you can see from this example those exceptions are callable WSGI applications. However, they are not Werkzeug response objects. You can get a response object by calling ``get_response()`` on a HTTP exception. Keep in mind that you may have to pass an environ (WSGI) or scope (ASGI) to ``get_response()`` because some errors fetch additional information relating to the request. If you want to hook in a different exception page to say, a 404 status code, you can add a second except for a specific subclass of an error: .. code-block:: python @Request.application def application(request): try: return view(request) except NotFound as e: return not_found(request) except HTTPException as e: return e

Class Aborter When passed a dict of code -> exception items it can be used as callable that raises exceptions. If the first argument to the callable is an integer it will be looked up in the mapping, if it's a WSGI application it will be raised in a proxy exception.
Exception BadGateway *502* `Bad Gateway`
Exception BadHost Raised if the submitted host is badly formatted.
Exception BadRequest *400* `Bad Request`
Exception BadRequestKeyError An exception that is used to signal both a :exc:`KeyError` and a :exc:`BadRequest`. Used by many of the datastructures.
Exception ClientDisconnected Internal exception that is raised if Werkzeug detects a disconnected client. Since the client is already gone at that point attempting to send the error message to the client might not work and might ultimately result in another exception in the server...
Exception Conflict *409* `Conflict`
Exception ExpectationFailed *417* `Expectation Failed`
Exception FailedDependency *424* `Failed Dependency`
Exception Forbidden *403* `Forbidden`
Exception GatewayTimeout *504* `Gateway Timeout`
Exception Gone *410* `Gone`
Exception HTTPException The base class for all HTTP exceptions. This exception can be called as a WSGI application to render a default error page or you can catch the subclasses of it independently and render nicer error messages.
Exception HTTPVersionNotSupported *505* `HTTP Version Not Supported`
Exception ImATeapot *418* `I'm a teapot`
Exception InternalServerError *500* `Internal Server Error`
Exception LengthRequired *411* `Length Required`
Exception Locked *423* `Locked`
Exception MethodNotAllowed *405* `Method Not Allowed`
Exception NotAcceptable *406* `Not Acceptable`
Exception NotFound *404* `Not Found`
Exception NotImplemented *501* `Not Implemented`
Exception PreconditionFailed *412* `Precondition Failed`
Exception PreconditionRequired *428* `Precondition Required`
Exception RequestedRangeNotSatisfiable *416* `Requested Range Not Satisfiable`
Exception RequestEntityTooLarge *413* `Request Entity Too Large`
Exception RequestHeaderFieldsTooLarge *431* `Request Header Fields Too Large`
Exception RequestTimeout *408* `Request Timeout`
Exception RequestURITooLarge *414* `Request URI Too Large`
Exception SecurityError Raised if something triggers a security error. This is otherwise exactly like a bad request error.
Exception ServiceUnavailable *503* `Service Unavailable`
Exception TooManyRequests *429* `Too Many Requests`
Exception Unauthorized *401* ``Unauthorized``
Exception UnavailableForLegalReasons *451* `Unavailable For Legal Reasons`
Exception UnprocessableEntity *422* `Unprocessable Entity`
Exception UnsupportedMediaType *415* `Unsupported Media Type`
Function abort Raises an :py:exc:`HTTPException` for the given status code or WSGI application.
Variable default_exceptions Undocumented
Exception _RetryAfter Adds an optional ``retry_after`` parameter which will set the ``Retry-After`` header. May be an :class:`int` number of seconds or a :class:`~datetime.datetime`.
Function _find_exceptions Undocumented
Variable _aborter Undocumented
def abort(status: t.Union[int, Response], *args: t.Any, **kwargs: t.Any) -> te.NoReturn: (source)

Raises an :py:exc:`HTTPException` for the given status code or WSGI application. If a status code is given, it will be looked up in the list of exceptions and will raise that exception. If passed a WSGI application, it will wrap it in a proxy WSGI exception and raise that:: abort(404) # 404 Not Found abort(Response('Hello World'))

default_exceptions: t.Dict[int, t.Type[HTTPException]] = (source)

Undocumented

def _find_exceptions(): (source)

Undocumented

Undocumented