コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 23 for detail (0.015 sec.)
Simple OAuth2 with Password and Bearer 11646
Simple OAuth2 with Password and Bearer Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Now let's build from the previous chapter and add the missing parts to have ... that declares a specific permission required. It doesn't matter if it has other characters like : or if it is a URL. Those details are implementation specific. For OAuth2 they are just strings. Code to get the username and password Now let's use the ut ... )]): user = fake_decode_token ( token ) if not user : raise HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Invalid authentication credentials" , headers = { "WWW-Authenticate" : "Bearer" }, ) return user async def get_current_ ... nnotated [ User , Depends ( get_current_user )], ): if current_user . disabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login ( form_data : Annotated [ OAuth2PasswordR ...
https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
SQL (Relational) Databases 11612
SQL (Relational) Databases Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI doesn't require you to use a SQL (relational) database. But you can use any data ... n : SessionDep ) -> Hero : hero = session . get ( Hero , hero_id ) if not hero : raise HTTPException ( status_code = 404 , detail = "Hero not found" ) return hero @app . delete ( "/heroes/ {hero_id} " ) def delete_hero ( hero_id : int , session : Sessi ... onDep ): hero = session . get ( Hero , hero_id ) if not hero : raise HTTPException ( status_code = 404 , detail = "Hero not found" ) session . delete ( hero ) session . commit () return { "ok" : True } ? Other versions and variants Py ... n : SessionDep ) -> Hero : hero = session . get ( Hero , hero_id ) if not hero : raise HTTPException ( status_code = 404 , detail = "Hero not found" ) return hero @app . delete ( "/heroes/ {hero_id} " ) def delete_hero ( hero_id : int , session : Sessi ...
https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
OAuth2 scopes 11227
OAuth2 scopes Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use OAuth2 scopes directly with FastAPI , they are integrated to work seamlessly. This would ... that declares a specific permission required. It doesn't matter if it has other characters like : or if it is a URL. Those details are implementation specific. For OAuth2 they are just strings. Global view First, let's quickly see the parts that change ... lse : authenticate_value = "Bearer" credentials_exception = HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Could not validate credentials" , headers = { "WWW-Authenticate" : authenticate_value }, ) try : payload = jwt . decode ... opes . scopes : if scope not in token_data . scopes : raise HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Not enough permissions" , headers = { "WWW-Authenticate" : authenticate_value }, ) return user async def get_current_ac ...
https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
テスト 11093
テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を ... ( item_id : str , x_token : str = Header ()): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if item_id not in fake_db : raise HTTPException ( status_code = 404 , detail = "Item not foun ... em ( item : Item , x_token : str = Header ()): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if item . id in fake_db : raise HTTPException ( status_code = 409 , detail = "Item already ex ... str , x_token : Annotated [ str , Header ()]): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if item_id not in fake_db : raise HTTPException ( status_code = 404 , detail = "Item not foun ...
https://man.mtool.work/fastapi/0.115/tutorial/testing/
path operationデコレータの依存関係 10506
path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、 ... fy_token ( x_token : str = Header ()): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : str = Header ()): if x_key != "fake-super-secret-key" : raise ... HTTPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key @app . get ( "/items/" , dependencies = [ Depends ( verify_token ), Depends ( veri ... token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Annotated [ str , Header ()]): if x_key != "fake-super-secret- ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 10121
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ ... : str = Depends ( oauth2_scheme )): credentials_exception = HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Could not validate credentials" , headers = { "WWW-Authenticate" : "Bearer" }, ) try : payload = jwt . decode ( token , ... urrent_user : User = Depends ( get_current_user )): if current_user . disabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login_for_access_token ( form_data : OAuth2Pass ... ata . username , form_data . password ) if not user : raise HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Incorrect username or password" , headers = { "WWW-Authenticate" : "Bearer" }, ) access_token_expires = timedelta ( min ...
https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
Global Dependencies 8529
Global Dependencies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . For some types of applications you might want to add dependencies to the whole application. Sim ... token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Annotated [ str , Header ()]): if x_key != "fake-super-secret- ... key" : raise HTTPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key app = FastAPI ( dependencies = [ Depends ( verify_token ), Depends ( verify_key )] ... token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Annotated [ str , Header ()]): if x_key != "fake-super-secret- ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/global-dependencies/
エラーハンドリング 8495
エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が ... / {item_id} " ) async def read_item ( item_id : str ): if item_id not in items : raise HTTPException ( status_code = 404 , detail = "Item not found" ) return { "item" : items [ item_id ]} コード内での HTTPException の発生 HTTPException は通常のPythonの ... / {item_id} " ) async def read_item ( item_id : str ): if item_id not in items : raise HTTPException ( status_code = 404 , detail = "Item not found" ) return { "item" : items [ item_id ]} レスポンス結果 クライアントが http://example.com/items/foo ( it ... い item_id "bar" )をリクエストした場合、HTTPステータスコード404("not found"エラー)と以下のJSONレスポンスが返されます: { "detail" : "Item not found" } 豆知識 HTTPException を発生させる際には、 str だけでなく、JSONに変換できる任意の値を detail パラメー ...
https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
Bigger Applications - Multiple Files 8294
Bigger Applications - Multiple Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you are building an application or a web API, it's rarely the case that you ... token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( stat ... us_code = 400 , detail = "No Jessica token provided" ) app/dependencies.py from fastapi import Header , HTTPException from typing_extensions impo ... token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( stat ...
https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
Custom Request and APIRoute class 7976
Custom Request and APIRoute class Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In some cases, you may want to override the logic used by the Request and APIRout ... p . post ( "/sum" ) async def sum_numbers ( numbers : List [ int ] = Body ()): return { "sum" : sum ( numbers )} Technical Details A Request has a request.scope attribute, that's just a Python dict containing the metadata related to the request. A Requ ... ry : return await original_route_handler ( request ) except RequestValidationError as exc : body = await request . body () detail = { "errors" : exc . errors (), "body" : body . decode ()} raise HTTPException ( status_code = 422 , detail = detail ) ret ... ry : return await original_route_handler ( request ) except RequestValidationError as exc : body = await request . body () detail = { "errors" : exc . errors (), "body" : body . decode ()} raise HTTPException ( status_code = 422 , detail = detail ) ret ...
https://man.mtool.work/fastapi/0.115/how-to/custom-request-and-route/
PREV 1 2 3 NEXT