コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 11 for exception (0.010 sec.)
OAuth2 scopes 12198
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 ... import datetime , timedelta , timezone from typing import Annotated import jwt from fastapi import Depends , FastAPI , HTTPException , Security , status from fastapi.security import ( OAuth2PasswordBearer , OAuth2PasswordRequestForm , SecurityScopes , ) f ... rom jwt.exceptions import InvalidTokenError from passlib.context import CryptContext from pydantic import BaseModel , ValidationError # to g ... authenticate_value = f 'Bearer scope=" { security_scopes . scope_str } "' else : authenticate_value = "Bearer" credentials_exception = HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Could not validate credentials" , headers = { " ...
https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 12020
パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ ... ime import datetime , timedelta , timezone from typing import Union import jwt from fastapi import Depends , FastAPI , HTTPException , status from fastapi.security import OAuth2PasswordBearer , OAuth2PasswordRequestForm from jwt.exceptions import InvalidT ... orithm = ALGORITHM ) return encoded_jwt async def get_current_user ( token : str = Depends ( oauth2_scheme )): credentials_exception = HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Could not validate credentials" , headers = { " ... oken , SECRET_KEY , algorithms = [ ALGORITHM ]) username = payload . get ( "sub" ) if username is None : raise credentials_exception token_data = TokenData ( username = username ) except InvalidTokenError : raise credentials_exception user = get_user ( fa ...
https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
エラーハンドリング 10918
エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が ... コードは、クライアントからのエラーがあったことを意味します。 "404 Not Found" のエラー(およびジョーク)を覚えていますか? HTTPException の使用 HTTPレスポンスをエラーでクライアントに返すには、 HTTPException を使用します。 HTTPException のインポート Python 3.8 ... + from fastapi import FastAPI , HTTPException app = FastAPI () items = { "foo" : "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 ]} コード内での HTTPException の発生 H ...
https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
yieldを持つ依存関係 8393
yieldを持つ依存関係 FastAPIは、いくつかの 終了後の追加のステップ を行う依存関係をサポートしています。 これを行うには、 return の代わりに yield を使い、その後に追加のステップを書きます。 豆知識 yield は必ず一度だけ使用するようにしてください。 ... たりするコードがあった場合、依存関係の中で例外を受け取ることになります。 そのため、依存関係の中にある特定の例外を except SomeException で探すことができます。 同様に、 finally を用いて例外があったかどうかにかかわらず、終了ステップを確実に実行することができま ... これはPythonの Context Managers のおかげで動作します。 FastAPI はこれを実現するために内部的に使用しています。 yield と HTTPException を持つ依存関係 yield と例外をキャッチする try ブロックを持つことができる依存関係を使用することができることがわかりました。 ... yield の後の終了コードで HTTPException などを発生させたくなるかもしれません。しかし それはうまくいきません yield を持つ依存関係の終了コードは 例外ハンドラ の 後に ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-with-yie...
Release Notes 7984
Release Notes Latest Changes 0.115.11 Fixes ? Add docs examples and tests (support) for Annotated custom validations, like AfterValidator , revert #13440 . PR #13442 by @tiangolo . New docs: Query Parameters and String Validations - Custom ... docs/uk/docs/tutorial/testing.md . PR #13371 by @valentinDruzhinin . 0.115.9 Fixes ? Ensure that HTTPDigest only raises an exception when auto_error is True . PR #2939 by @arthurio . Refactors ✅ Simplify tests for query_params_str_validations . PR #13218 ... 13033 by @tiangolo . ? Update sponsors: remove Codacy. PR #13032 by @tiangolo . 0.115.6 Fixes ? Preserve traceback when an exception is raised in sync dependency with yield . PR #5823 by @sombek . Refactors ♻️ Update tests and internals for compatibility ... r/docs/tutorial/request-forms.md . PR #11553 by @hasansezertasan . ? Add Portuguese translation for docs/pt/docs/reference/exceptions.md . PR #11834 by @lucasbalieiro . ? Add Portuguese translation for docs/pt/docs/tutorial/dependencies/global-dependencie ...
https://man.mtool.work/fastapi/0.115/release-notes/
Exceptions - HTTPException and WebSocketException 7877
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 WebSocketExcept ... ion These exceptions can be imported directly from fastapi : from fastapi import HTTPException , WebSocketException ::: fastapi.HTTPException ... ::: fastapi.WebSocketException ...
https://man.mtool.work/fastapi/0.115/reference/exceptions/
FastAPI class 7877
FastAPI class Here's the reference information for the FastAPI class, with all its parameters, attributes and methods. You can import the FastAPI class directly from fastapi : from fastapi import FastAPI ::: fastapi.FastAPI options: members ... penapi - websocket - include_router - get - put - post - delete - options - head - patch - trace - on_event - middleware - exception_handler ...
https://man.mtool.work/fastapi/0.115/reference/fastapi/
Custom Request and APIRoute class 7841
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 ... request body will be automatically decompressed when it is loaded by FastAPI when needed. Accessing the request body in an exception handler Tip To solve this same problem, it's probably a lot easier to use the body in a custom handler for RequestValidati ... it shows how to interact with the internal components. We can also use this same approach to access the request body in an exception handler. All we need to do is handle the request inside a try / except block: Python 3.8+ from typing import Callable , Li ... st from fastapi import Body , FastAPI , HTTPException , Request , Response from fastapi.exceptions import RequestValidationError from fastapi.routing import APIRoute class Vali ...
https://man.mtool.work/fastapi/0.115/how-to/custom-request-and-route/
WebSockets 7735
WebSockets When defining WebSockets, you normally declare a parameter of type WebSocket and with it you can read data from the client and send data to it. It is provided directly by Starlette, but you can import it from fastapi : from fasta ... ext - iter_bytes - iter_json - send_text - send_bytes - send_json - close When a client disconnects, a WebSocketDisconnect exception is raised, you can catch it. You can import it directly form fastapi : from fastapi import WebSocketDisconnect ::: fastapi ...
https://man.mtool.work/fastapi/0.115/reference/websockets/
Advanced Middleware 7539
Advanced Middleware Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In the main tutorial you read how to add Custom Middleware to your application. And then you al ... y Starlette) provides a simpler way to do it that makes sure that the internal middlewares handle server errors and custom exception handlers work properly. For that, you use app.add_middleware() (as in the example for CORS). from fastapi import FastAPI f ...
https://man.mtool.work/fastapi/0.115/advanced/middleware/
PREV 1 2 NEXT