cost 192 ms
如何在公開端口的 docker 容器中運行 uvicorn?

[英]How do I run uvicorn in a docker container that exposes the port?

我正在 windows/ubuntu 的 docker 容器中開發一個 fastapi(代碼如下)。 當我通過在終端中運行python -m uvicorn app:app --reload然后導航到127.0.0.1:8000/home來測試容器外的應用程序時,一切正常: 但是,當我啟動 doc ...

如何將自定義標頭添加到 fastapi 中的 static 文件

[英]How to add custom headers to static files in fastapi

我們使用以下方法從目錄app.mount("/static", StaticFiles(directory="static"), name="static")掛載 static 文件在向客戶端發送響應之前,我們使用通用方法為安全相關步驟發送了 api 的自定義標頭。 有沒有辦法將安全標頭發送到 cs ...

pytest 在單獨的進程中請求 fastapi

[英]pytest requests to fastapi in a separate process

我正在嘗試對使用 FastAPI 編寫的 API 進行工作測試。 我在一個單獨的進程中啟動該服務,使用對服務的請求運行測試,並檢查結果是否符合預期。 我已將關鍵部分提取到 PD 中的最小工作示例中。 使用主文件運行 MWE 工作正常。 但是,測試失敗了。 為什么測試會失敗? 我們應該如何測試 AP ...

fastAPI SQLmodel MultipleResultsFound:當恰好需要一行時找到多行

[英]fastAPI SQLmodel MultipleResultsFound: Multiple rows were found when exactly one was required

這是我刪除的 function。 我想刪除 session_id 匹配的所有記錄。 但它拋出以下錯誤MultipleResultsFound: Multiple rows were found when exactly one was required 我怎樣才能一次刪除多行。 我嘗試使用 但它說 ...

如何對 Pydantic model 的參數施加特定約束?

[英]How to place specific constraints on the parameters of a Pydantic model?

如何對 Pydantic model 的參數施加特定約束? 特別是,我想: start_date必須至少為"2019-01-01" end_date必須大於start_date code必須是集合中的一個值,並且只能是其中一個 cluster必須是集合中的一個且僅是其中一個值我使用的代碼如下 ...

FastAPI AttributeError: 'Depends' object 沒有屬性 'query'

[英]FastAPI AttributeError: 'Depends' object has no attribute 'query'

我正在嘗試使用快速 API 訪問我的數據庫。如果在端點之外訪問它,我會遇到一些問題。 我正在嘗試訪問數據庫並檢索允許的電子郵件。 我可以在 get/post (/refresh) 端點執行此操作,但不能在路由 (/token) 中執行此操作,它會拋出錯誤:''Depends' object has ...

從 Angular 調用的 FastAPI Post APIs - 相同的代碼:不同的行為

[英]FastAPI Post APIs invoked from Angular - Same code : Different Behaviour

我是 Angular 和 FastApi 的新手。 我一直在嘗試從 Angular 屏幕調用 2 個單獨的 FastApi 端點的場景。 我將相同的 Python 代碼用於 POST API 在 2 個單獨的 .py 文件中。 下面提供的代碼。 以上python服務運行在localhost,8000 ...

如何使用fastapi和SQLAlchemy更新信息

[英]How to update the information using fastapi and SQLAlchemy

我正在使用 FastAPI 和 SQLAlchemy。我有兩個 ORM 模型用戶和具有外鍵關系的 user_profiles。 我正在使用一個 model 向用戶和 user_profiles 插入數據 我的用戶請求 model 更新數據: 我的問題是如何在 UserRequest 中包含 user ...

在 docker 中無法訪問容器構成最簡單的示例

[英]container not reachable in docker compose simplest example

docker 撰寫文檔說: 服務的每個容器都加入 default.network 並且可以被該網絡上的其他容器訪問,並且可以被它們在與容器名稱相同的主機名處發現。 但我創建了一個非常簡單的應用程序,但我無法開始工作。 我的腳本是:(也在這里) frontend/index.html<!DOC ...

扁平嵌套 Pydantic model

[英]Flatten nested Pydantic model

from typing import Union from pydantic import BaseModel, Field class Category(BaseModel): name: str = Field(alias="name") class OrderItems(Bas ...

如何使用 FastAPI 將 dataframe 正確返回為 JSON?

[英]How to properly return dataframe as JSON using FastAPI?

我使用返回 JSON 的 FastAPI 創建了一個 API。首先,我曾經使用 Pandas.to_json() 方法將 Dataframe 轉換為 JSON ,這使我能夠選擇正確的“東方”參數。 這保存了一個 .json 文件,然后打開它使 fastAPI 返回它,如下所示: 這工作得很好,但我 ...

相當於 FastAPI 中的 flask.request.url

[英]equivalent of flask.request.url in FastAPI

我正在嘗試將 google oauth2 示例代碼從 python flask 更改為 FastAPI。 這是代碼 the line is authorization_response = flask.request.url the value of it is "http://localhos ...

Fastapi限制上傳文件大小問題

[英]Fastapi Limiting Upload File Size Problem

我想用 fastapi 設置文件上傳限制,但我有一個問題,我無法在上傳整個文件之前檢查文件的大小。 例如,如果有 15 MB 的文件上傳限制,而這個人上傳的文件超過 15 MB,我想阻止他們上傳到服務器。 我不想使用 Content-Length 來阻止它,因為它不會阻止任何攻擊。 我找到了不同的解 ...

CORS 政策阻止了從來源“http://0.0.0.0:8000”訪問“http://localhost:8000/api/v1”

[英]Access to fetch at 'http://localhost:8000/api/v1' from origin 'http://0.0.0.0:8000' has been blocked by CORS policy

這個問題有詳細記錄,但我的嘗試沒有成功......歡迎任何建議! Github 上的 cookiecutter 項目: Buuntu/fastapi-react 重現錯誤cookiecutter gh:Buuntu/fastapi-react --no-input cd fastapi-reac ...

在數據庫中創建新記錄時客戶端發送的外鍵應該是什么?

[英]What should be the foreign key that the client sends when creating a new record in a database?

我正在使用 python、fastapi 和 postgresql 制作一個 web 應用程序。數據庫中有兩個相關實體:“部門”和“用戶”,具有一對多關系: 這些是學究式的模型: 因此,在應用程序中創建用戶時,必須發送指向用戶所屬部門的外鍵。 按照慣例,這個外鍵是部門的id(Pk),但是我想也許當 ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM