Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 83 for 404 (0.14 sec)

  1. tests/test_tutorial/test_additional_responses/test_tutorial001.py

        assert response.json() == {"id": "foo", "value": "there goes my hero"}
    
    
    def test_path_operation_not_found():
        response = client.get("/items/bar")
        assert response.status_code == 404, response.text
        assert response.json() == {"message": "Item not found"}
    
    
    def test_openapi_schema():
        response = client.get("/openapi.json")
        assert response.status_code == 200, response.text
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 4.3K bytes
    - Viewed (0)
  2. tests/test_tutorial/test_additional_responses/test_tutorial003.py

        assert response.json() == {"id": "foo", "value": "there goes my hero"}
    
    
    def test_path_operation_not_found():
        response = client.get("/items/bar")
        assert response.status_code == 404, response.text
        assert response.json() == {"message": "Item not found"}
    
    
    def test_openapi_schema():
        response = client.get("/openapi.json")
        assert response.status_code == 200, response.text
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Fri Jun 30 18:25:16 GMT 2023
    - 4.5K bytes
    - Viewed (0)
  3. docs_src/handling_errors/tutorial002.py

    app = FastAPI()
    
    items = {"foo": "The Foo Wrestlers"}
    
    
    @app.get("/items-header/{item_id}")
    async def read_item_header(item_id: str):
        if item_id not in items:
            raise HTTPException(
                status_code=404,
                detail="Item not found",
                headers={"X-Error": "There goes my error"},
            )
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Mar 26 19:09:53 GMT 2020
    - 404 bytes
    - Viewed (0)
  4. docs/fr/docs/advanced/additional-responses.md

    **FastAPI** prendra ce modèle, générera son schéma JSON et l'inclura au bon endroit dans OpenAPI.
    
    Par exemple, pour déclarer une autre réponse avec un code HTTP `404` et un modèle Pydantic `Message`, vous pouvez écrire :
    
    ```Python hl_lines="18 22"
    {!../../../docs_src/additional_responses/tutorial001.py!}
    ```
    
    !!! note "Remarque"
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 9.6K bytes
    - Viewed (0)
  5. tests/test_router_redirect_slashes.py

        response = client.get("/hello/", follow_redirects=False)
        assert response.status_code == 200
    
        response = client.get("/hello", follow_redirects=False)
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Jun 22 10:37:50 GMT 2023
    - 974 bytes
    - Viewed (0)
  6. tests/test_tutorial/test_dependencies/test_tutorial008d_an.py

        client = TestClient(app)
        return client
    
    
    def test_get_no_item(client: TestClient):
        response = client.get("/items/foo")
        assert response.status_code == 404, response.text
        assert response.json() == {"detail": "Item not found, there's only a plumbus here"}
    
    
    def test_get(client: TestClient):
        response = client.get("/items/plumbus")
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sat Feb 24 23:06:37 GMT 2024
    - 1.2K bytes
    - Viewed (0)
  7. docs/zh/docs/tutorial/handling-errors.md

    需要向客户端返回错误提示的场景主要如下:
    
    - 客户端没有执行操作的权限
    - 客户端没有访问资源的权限
    - 客户端要访问的项目不存在
    - 等等 ...
    
    遇到这些情况时,通常要返回 **4XX**(400 至 499)**HTTP 状态码**。
    
    **4XX** 状态码与表示请求成功的 **2XX**(200 至 299) HTTP 状态码类似。
    
    只不过,**4XX** 状态码表示客户端发生的错误。
    
    大家都知道**「404 Not Found」**错误,还有调侃这个错误的笑话吧?
    
    ## 使用 `HTTPException`
    
    向客户端返回 HTTP 错误响应,可以使用 `HTTPException`。
    
    ### 导入 `HTTPException`
    
    ```Python hl_lines="1"
    {!../../../docs_src/handling_errors/tutorial001.py!}
    
    ```
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 8.4K bytes
    - Viewed (0)
  8. docs_src/app_testing/app_b/main.py

        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)
    async def create_item(item: Item, x_token: str = Header()):
        if x_token != fake_secret_token:
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Tue Jan 09 14:44:08 GMT 2024
    - 1.1K bytes
    - Viewed (0)
  9. docs_src/app_testing/app_b_an/test_main.py

        assert response.json() == {"detail": "Invalid X-Token header"}
    
    
    def test_read_nonexistent_item():
        response = client.get("/items/baz", headers={"X-Token": "coneofsilence"})
        assert response.status_code == 404
        assert response.json() == {"detail": "Item not found"}
    
    
    def test_create_item():
        response = client.post(
            "/items/",
            headers={"X-Token": "coneofsilence"},
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Wed Mar 13 19:07:10 GMT 2024
    - 1.8K bytes
    - Viewed (0)
  10. docs_src/additional_responses/tutorial003.py

        id: str
        value: str
    
    
    class Message(BaseModel):
        message: str
    
    
    app = FastAPI()
    
    
    @app.get(
        "/items/{item_id}",
        response_model=Item,
        responses={
            404: {"model": Message, "description": "The item was not found"},
            200: {
                "description": "Item requested by ID",
                "content": {
                    "application/json": {
    Python
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Mar 26 19:09:53 GMT 2020
    - 837 bytes
    - Viewed (0)
Back to top