Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 110 for HTTPException (0.23 sec)

  1. docs/en/docs/tutorial/handling-errors.md

        "size": "XL"
      }
    }
    ```
    
    #### FastAPI's `HTTPException` vs Starlette's `HTTPException`
    
    **FastAPI** has its own `HTTPException`.
    
    And **FastAPI**'s `HTTPException` error class inherits from Starlette's `HTTPException` error class.
    
    The only difference is that **FastAPI**'s `HTTPException` accepts any JSON-able data for the `detail` field, while Starlette's `HTTPException` only accepts strings for it.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 9.1K bytes
    - Viewed (0)
  2. docs_src/app_testing/app_b_py310/main.py

            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 found")
        return fake_db[item_id]
    
    
    @app.post("/items/", response_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")
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Jan 09 14:44:08 GMT 2024
    - 1.1K bytes
    - Viewed (0)
  3. docs_src/app_testing/app_b_an/main.py

    @app.get("/items/{item_id}", response_model=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(status_code=404, detail="Item not found")
        return fake_db[item_id]
    
    
    @app.post("/items/", response_model=Item)
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat Mar 18 12:29:59 GMT 2023
    - 1.2K bytes
    - Viewed (0)
  4. docs/pt/docs/tutorial/handling-errors.md

        "title": "towel",
        "size": "XL"
      }
    }
    ```
    
    #### O `HTTPException` do FastAPI vs o `HTTPException` do Starlette.
    
    O **FastAPI** tem o seu próprio `HTTPException`.
    
    E a classe de erro `HTTPException` do **FastAPI** herda da classe de erro do `HTTPException` do Starlette.
    
    A diferença entre os dois é a de que o `HTTPException` do **FastAPI** permite que você adicione *headers* que serão incluídos nas *responses*.
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 10K bytes
    - Viewed (0)
  5. docs/zh/docs/tutorial/handling-errors.md

      }
    }
    
    ```
    
    ### FastAPI `HTTPException` vs Starlette `HTTPException`
    
    **FastAPI** 也提供了自有的 `HTTPException`。
    
    **FastAPI** 的 `HTTPException` 继承自 Starlette 的 `HTTPException` 错误类。
    
    它们之间的唯一区别是,**FastAPI** 的 `HTTPException` 可以在响应中添加响应头。
    
    OAuth 2.0 等安全工具需要在内部调用这些响应头。
    
    因此你可以继续像平常一样在代码中触发 **FastAPI** 的 `HTTPException` 。
    
    但注册异常处理器时,应该注册到来自 Starlette 的 `HTTPException`。
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.4K bytes
    - Viewed (0)
  6. docs/en/docs/tutorial/dependencies/dependencies-with-yield.md

        **FastAPI** uses them internally to achieve this.
    
    ## Dependencies with `yield` and `HTTPException`
    
    You saw that you can use dependencies with `yield` and have `try` blocks that catch exceptions.
    
    The same way, you could raise an `HTTPException` or similar in the exit code, after the `yield`.
    
    !!! tip
    
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat Feb 24 23:06:37 GMT 2024
    - 14.1K bytes
    - Viewed (0)
  7. docs_src/sql_databases/sql_app_py310/main.py

    from fastapi import Depends, FastAPI, HTTPException
    from sqlalchemy.orm import Session
    
    from . import crud, models, schemas
    from .database import SessionLocal, engine
    
    models.Base.metadata.create_all(bind=engine)
    
    app = FastAPI()
    
    
    # Dependency
    def get_db():
        db = SessionLocal()
        try:
            yield db
        finally:
            db.close()
    
    
    @app.post("/users/", response_model=schemas.User)
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Jan 07 14:11:31 GMT 2022
    - 1.6K bytes
    - Viewed (0)
  8. docs_src/dependencies/tutorial006_an.py

    from typing_extensions import Annotated
    
    app = 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, Header()]):
        if x_key != "fake-super-secret-key":
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Sat Mar 18 12:29:59 GMT 2023
    - 643 bytes
    - Viewed (0)
  9. docs/em/docs/tutorial/handling-errors.md

        "size": "XL"
      }
    }
    ```
    
    #### FastAPI `HTTPException` 🆚 💃 `HTTPException`
    
    **FastAPI** ✔️ 🚮 👍 `HTTPException`.
    
    & **FastAPI**'Ⓜ `HTTPException` ❌ 🎓 😖 ⚪️➡️ 💃 `HTTPException` ❌ 🎓.
    
    🕴 🔺, 👈 **FastAPI**'Ⓜ `HTTPException` ✔ 👆 🚮 🎚 🔌 📨.
    
    👉 💪/⚙️ 🔘 ✳ 2️⃣.0️⃣ & 💂‍♂ 🚙.
    
    , 👆 💪 🚧 🙋‍♀ **FastAPI**'Ⓜ `HTTPException` 🛎 👆 📟.
    
    ✋️ 🕐❔ 👆 ® ⚠ 🐕‍🦺, 👆 🔜 ® ⚫️ 💃 `HTTPException`.
    Plain Text
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.3K bytes
    - Viewed (0)
  10. docs_src/dependencies/tutorial008b_an_py39.py

    from fastapi import Depends, FastAPI, HTTPException
    
    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:
    Python
    - Registered: Sun Apr 21 07:19:11 GMT 2024
    - Last Modified: Tue Dec 26 20:37:34 GMT 2023
    - 775 bytes
    - Viewed (0)
Back to top