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 |
|
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 |
|
*502* `Bad Gateway` |
Exception |
|
Raised if the submitted host is badly formatted. |
Exception |
|
*400* `Bad Request` |
Exception |
|
An exception that is used to signal both a :exc:`KeyError` and a :exc:`BadRequest`. Used by many of the datastructures. |
Exception |
|
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 |
|
*409* `Conflict` |
Exception |
|
*417* `Expectation Failed` |
Exception |
|
*424* `Failed Dependency` |
Exception |
|
*403* `Forbidden` |
Exception |
|
*504* `Gateway Timeout` |
Exception |
|
*410* `Gone` |
Exception |
|
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 |
|
*505* `HTTP Version Not Supported` |
Exception |
|
*418* `I'm a teapot` |
Exception |
|
*500* `Internal Server Error` |
Exception |
|
*411* `Length Required` |
Exception |
|
*423* `Locked` |
Exception |
|
*405* `Method Not Allowed` |
Exception |
|
*406* `Not Acceptable` |
Exception |
|
*404* `Not Found` |
Exception |
|
*501* `Not Implemented` |
Exception |
|
*412* `Precondition Failed` |
Exception |
|
*428* `Precondition Required` |
Exception |
|
*416* `Requested Range Not Satisfiable` |
Exception |
|
*413* `Request Entity Too Large` |
Exception |
|
*431* `Request Header Fields Too Large` |
Exception |
|
*408* `Request Timeout` |
Exception |
|
*414* `Request URI Too Large` |
Exception |
|
Raised if something triggers a security error. This is otherwise exactly like a bad request error. |
Exception |
|
*503* `Service Unavailable` |
Exception |
|
*429* `Too Many Requests` |
Exception |
|
*401* ``Unauthorized`` |
Exception |
|
*451* `Unavailable For Legal Reasons` |
Exception |
|
*422* `Unprocessable Entity` |
Exception |
|
*415* `Unsupported Media Type` |
Function | abort |
Raises an :py:exc:`HTTPException` for the given status code or WSGI application. |
Variable | default |
Undocumented |
Exception | _ |
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 |
Undocumented |
Variable | _aborter |
Undocumented |
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'))