- Sort Score
- Result 10 results
- Languages All
Results 1 - 10 of 17 for Chandler (0.5 sec)
-
docs_src/handling_errors/tutorial006.py
from fastapi import FastAPI, HTTPException from fastapi.exception_handlers import ( http_exception_handler, request_validation_exception_handler, ) from fastapi.exceptions import RequestValidationError from starlette.exceptions import HTTPException as StarletteHTTPException app = FastAPI() @app.exception_handler(StarletteHTTPException) async def custom_http_exception_handler(request, exc): print(f"OMG! An HTTP error!: {repr(exc)}")
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Sun Aug 09 11:10:33 GMT 2020 - 928 bytes - Viewed (0) -
docs_src/custom_request_and_route/tutorial003.py
from fastapi.routing import APIRoute class TimedRoute(APIRoute): def get_route_handler(self) -> Callable: original_route_handler = super().get_route_handler() async def custom_route_handler(request: Request) -> Response: before = time.time() response: Response = await original_route_handler(request) duration = time.time() - before
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 1K bytes - Viewed (0) -
docs_src/handling_errors/tutorial005.py
from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse from pydantic import BaseModel app = FastAPI() @app.exception_handler(RequestValidationError) async def validation_exception_handler(request: Request, exc: RequestValidationError): return JSONResponse( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 667 bytes - Viewed (0) -
tests/test_ws_router.py
def test_depend_err_handler(): """ Verify that it is possible to write custom WebSocket middleware to catch errors """ async def custom_handler(websocket: WebSocket, exc: CustomError) -> None: await websocket.close(1002, "foo") myapp = make_app(exception_handlers={CustomError: custom_handler}) client = TestClient(myapp)
Python - Registered: Sun Apr 28 07:19:10 GMT 2024 - Last Modified: Sun Jun 11 19:08:14 GMT 2023 - 7.5K bytes - Viewed (0) -
docs_src/custom_request_and_route/tutorial002.py
from fastapi.routing import APIRoute class ValidationErrorLoggingRoute(APIRoute): def get_route_handler(self) -> Callable: original_route_handler = super().get_route_handler() async def custom_route_handler(request: Request) -> Response: try: return await original_route_handler(request) except RequestValidationError as exc: body = await request.body()
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Fri May 13 23:38:22 GMT 2022 - 932 bytes - Viewed (0) -
docs_src/handling_errors/tutorial003.py
from fastapi.responses import JSONResponse class UnicornException(Exception): def __init__(self, name: str): self.name = name app = FastAPI() @app.exception_handler(UnicornException) async def unicorn_exception_handler(request: Request, exc: UnicornException): return JSONResponse( status_code=418, content={"message": f"Oops! {exc.name} did something. There goes a rainbow..."}, )
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 626 bytes - Viewed (0) -
tests/test_enforce_once_required_parameter.py
def _get_client_tag(client_id: Optional[str] = Query(None)) -> Optional[str]: if client_id is None: return None return f"{client_id}_tag" @app.get("/foo") def foo_handler( client_key: str = Depends(_get_client_key), client_tag: Optional[str] = Depends(_get_client_tag), ): return {"client_id": client_key, "client_tag": client_tag} client = TestClient(app)
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Fri Jun 30 18:25:16 GMT 2023 - 3.4K bytes - Viewed (0) -
tests/test_starlette_exception.py
assert response.json() == {"detail": "Item not found"} def test_no_body_status_code_exception_handlers(): response = client.get("/http-no-body-statuscode-exception") assert response.status_code == 204 assert not response.content def test_no_body_status_code_with_detail_exception_handlers(): response = client.get("/http-no-body-statuscode-with-detail-exception") assert response.status_code == 204
Python - Registered: Sun Apr 28 07:19:10 GMT 2024 - Last Modified: Fri Jun 30 18:25:16 GMT 2023 - 7.4K bytes - Viewed (0) -
tests/test_tutorial/test_websockets/test_tutorial003.py
from docs_src.websockets.tutorial003 import app, html client = TestClient(app) def test_get(): response = client.get("/") assert response.text == html def test_websocket_handle_disconnection(): with client.websocket_connect("/ws/1234") as connection, client.websocket_connect( "/ws/5678" ) as connection_two: connection.send_text("Hello from 1234")
Python - Registered: Sun Apr 28 07:19:10 GMT 2024 - Last Modified: Thu Jul 29 09:26:07 GMT 2021 - 872 bytes - Viewed (0) -
tests/test_tutorial/test_websockets/test_tutorial003_py39.py
return client @needs_py39 def test_get(client: TestClient, html: str): response = client.get("/") assert response.text == html @needs_py39 def test_websocket_handle_disconnection(client: TestClient): with client.websocket_connect("/ws/1234") as connection, client.websocket_connect( "/ws/5678" ) as connection_two: connection.send_text("Hello from 1234")
Python - Registered: Sun Apr 28 07:19:10 GMT 2024 - Last Modified: Sat Mar 18 12:29:59 GMT 2023 - 1.3K bytes - Viewed (0)