- Sort Score
- Result 10 results
- Languages All
Results 31 - 40 of 68 for exceptions (0.43 sec)
-
docs_src/handling_errors/tutorial003.py
from fastapi import FastAPI, Request 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,
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Thu Mar 26 19:09:53 GMT 2020 - 626 bytes - Viewed (0) -
docs_src/security/tutorial004_an_py310.py
username: str = payload.get("sub") if username is None: raise credentials_exception token_data = TokenData(username=username) except JWTError: raise credentials_exception user = get_user(fake_users_db, username=token_data.username) if user is None: raise credentials_exception return user async def get_current_active_user(
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Tue Mar 26 16:56:53 GMT 2024 - 4.1K bytes - Viewed (0) -
tests/test_ws_router.py
def test_depend_validation(): """ Verify that a validation in a dependency invokes the correct exception handler """ caught = [] @websocket_middleware async def catcher(websocket, call_next): try: return await call_next() except Exception as e: # pragma: no cover caught.append(e) raise
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/security/tutorial005_an.py
if username is None: raise credentials_exception token_scopes = payload.get("scopes", []) token_data = TokenData(scopes=token_scopes, username=username) except (JWTError, ValidationError): raise credentials_exception user = get_user(fake_users_db, username=token_data.username) if user is None: raise credentials_exception for scope in security_scopes.scopes:
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Tue Mar 26 16:56:53 GMT 2024 - 5.3K bytes - Viewed (0) -
docs_src/dependencies/tutorial008c_an.py
from fastapi import Depends, FastAPI, HTTPException from typing_extensions import Annotated app = FastAPI() class InternalError(Exception): pass def get_username(): try: yield "Rick" except InternalError: print("Oops, we didn't raise again, Britney 😱") @app.get("/items/{item_id}") def get_item(item_id: str, username: Annotated[str, Depends(get_username)]): if item_id == "portal-gun":
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Sat Feb 24 23:06:37 GMT 2024 - 710 bytes - Viewed (0) -
docs_src/dependencies/tutorial008b_an_py39.py
app = FastAPI() data = { "plumbus": {"description": "Freshly pickled plumbus", "owner": "Morty"}, "portal-gun": {"description": "Gun to create portals", "owner": "Rick"}, } class OwnerError(Exception): pass def get_username(): try: yield "Rick" except OwnerError as e: raise HTTPException(status_code=400, detail=f"Owner error: {e}") @app.get("/items/{item_id}")
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Tue Dec 26 20:37:34 GMT 2023 - 775 bytes - Viewed (0) -
tests/test_dependency_contextmanager.py
"bg": "not set", "sync_bg": "not set", } errors = [] async def get_state(): return state class AsyncDependencyError(Exception): pass class SyncDependencyError(Exception): pass class OtherDependencyError(Exception): pass async def asyncgen_state(state: Dict[str, str] = Depends(get_state)): state["/async"] = "asyncgen started" yield state["/async"]
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Sat Feb 24 23:06:37 GMT 2024 - 11.6K bytes - Viewed (0) -
tests/test_tutorial/test_dependencies/test_tutorial008d_an_py39.py
) @needs_py39 def test_internal_server_error(): from docs_src.dependencies.tutorial008d_an_py39 import app client = TestClient(app, raise_server_exceptions=False) response = client.get("/items/portal-gun") assert response.status_code == 500, response.text
Python - Registered: Sun Apr 28 07:19:10 GMT 2024 - Last Modified: Sat Feb 24 23:06:37 GMT 2024 - 1.3K bytes - Viewed (0) -
tests/test_custom_middleware_exception.py
from pathlib import Path from typing import Optional from fastapi import APIRouter, FastAPI, File, UploadFile from fastapi.exceptions import HTTPException from fastapi.testclient import TestClient app = FastAPI() router = APIRouter() class ContentSizeLimitMiddleware: """Content size limiting middleware for ASGI applications Args: app (ASGI application): ASGI application
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Thu Aug 25 21:44:40 GMT 2022 - 2.8K bytes - Viewed (0) -
tests/test_empty_router.py
import pytest from fastapi import APIRouter, FastAPI from fastapi.exceptions import FastAPIError from fastapi.testclient import TestClient app = FastAPI() router = APIRouter() @router.get("") def get_empty(): return ["OK"] app.include_router(router, prefix="/prefix") client = TestClient(app) def test_use_empty(): with client: response = client.get("/prefix")
Python - Registered: Sun May 05 07:19:11 GMT 2024 - Last Modified: Sun Jun 11 22:37:34 GMT 2023 - 805 bytes - Viewed (0)