コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 15 for raise (0.014 sec.)
OAuth2 scopes 11511
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 ... = jwt . decode ( token , SECRET_KEY , algorithms = [ ALGORITHM ]) username = payload . get ( "sub" ) if username is None : raise credentials_exception token_scopes = payload . get ( "scopes" , []) token_data = TokenData ( scopes = token_scopes , usern ... ame = username ) except ( InvalidTokenError , ValidationError ): raise credentials_exception user = get_user ( fake_users_db , username = token_data . username ) if user is None : raise credent ... ials_exception for scope in security_scopes . scopes : if scope not in token_data . scopes : raise HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Not enough permissions" , headers = { "WWW-Authen ...
https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
SQL (Relational) Databases 11268
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 ... " ) def read_hero ( hero_id : int , session : 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 de ... lete_hero ( hero_id : int , session : SessionDep ): 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 ... " ) def read_hero ( hero_id : int , session : 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 de ...
https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
Simple OAuth2 with Password and Bearer 11233
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 ... get_current_user ( token : Annotated [ str , Depends ( oauth2_scheme )]): user = fake_decode_token ( token ) if not user : raise HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Invalid authentication credentials" , headers = { ... get_current_active_user ( current_user : Annotated [ 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 logi ... ed [ OAuth2PasswordRequestForm , Depends ()]): user_dict = fake_users_db . get ( form_data . username ) if not user_dict : raise HTTPException ( status_code = 400 , detail = "Incorrect username or password" ) user = UserInDB ( ** user_dict ) hashed_pa ...
https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 10989
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ ... = jwt . decode ( token , SECRET_KEY , algorithms = [ ALGORITHM ]) username = payload . get ( "sub" ) if username is None : raise credentials_exception token_data = TokenData ( username = username ) except InvalidTokenError : raise credentials_exceptio ... n 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 ( current_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 logi ...
https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
path operationデコレータの依存関係 10258
path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、 ... PException app = FastAPI () async def verify_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 ()): i ... f x_key != "fake-super-secret-key" : raise HTTPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key @app . get ( "/items/" , dependencies = ... p = FastAPI () async def verify_token ( x_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 , H ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
テスト 8533
テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を ... esponse_model = Item ) async def read_main ( 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 ( ... esponse_model = Item ) async def create_item ( 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 ( st ... = Item ) async def read_main ( item_id : 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 ( ...
https://man.mtool.work/fastapi/0.115/tutorial/testing/
Exceptions - HTTPException and WebSocketException 8011
Exceptions - HTTPException and WebSocketException These are the exceptions that you can raise to show errors to the client. When you raise an exception, as would happen with normal Python, the rest of the execution is aborted. This way you ... can raise these exceptions from anywhere in the code to abort a request and show the error to the client. You can use: HTTPException ...
https://man.mtool.work/fastapi/0.115/reference/exceptions/
Global Dependencies 7976
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 ... port Annotated async def verify_token ( x_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 , H ... eader ()]): if x_key != "fake-super-secret-key" : raise HTTPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key app = FastAPI ( dependencies = [ Depend ... port Annotated async def verify_token ( x_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 , H ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/global-dependencies/
エラーハンドリング 7663
エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が ... "The Foo Wrestlers" } @app . get ( "/items/ {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 ]} コード内での HTTPExce ... 生 HTTPException は通常のPythonの例外であり、APIに関連するデータを追加したものです。 Pythonの例外なので、 return ではなく、 raise です。 これはまた、 path operation関数 の内部で呼び出しているユーティリティ関数の内部から HTTPException を発生させた場合、 ... "The Foo Wrestlers" } @app . get ( "/items/ {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 ]} レスポンス結果 クライ ...
https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
Bigger Applications - Multiple Files 7628
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 ... PException async def get_token_header ( x_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 toke ... n != "jessica" : raise HTTPException ( status_code = 400 , detail = "No Jessica token provided" ) app/dependencies.py from fastapi import Header ... Annotated async def get_token_header ( x_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 toke ...
https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
PREV 1 2 NEXT