我的主机上有一个 API 在端口 8000 上运行。同时,我有一个 docker compose 集群,其中有一个容器应该连接所述 API。为了获取请求的 url,我在 Windows 计算机上使用“host.docker.internal:8000”,效果非常好。但是,我有一个 Linux 部署服务器,其中“host.docker.internal”无法解析任何内容,导致 API 连接错误。我在stackoverflow 上的另一篇文章中看到,您通过在 Linux 上添加以下内容来解决此问题docker-compose.yaml
services:
service_name:
extra_hosts:
- host.docker.internal:host-gateway
Run Code Online (Sandbox Code Playgroud)
这将 docker0 IP 添加到/etc/hosts,但是当我尝试执行 GET 请求时,生成的消息是:
Failed to connect to host.docker.internal port 8000: Connection refused
我现在真的很困惑。我不知道这是否是防火墙问题、docker问题、docker compose问题、docker on linux问题。请帮忙...
我有一个具有以下文件结构的项目
\nproject\n|\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 App1/static/App1\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ts\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 js\n| \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n|\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 App2/static/App2\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ts\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 js\n| \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n|\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 App3/static/App3\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ts\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 js\n| \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\n|\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\nRun Code Online (Sandbox Code Playgroud)\n每个应用程序都需要在目录中找到已编译的 Typescript 文件ts才能进入js同一目录中的每个文件夹。为了使这项工作到目前为止,我tsconfig.json在“项目”目录的顶部找到了一个全局文件。然后,tsconfig.json在每个应用程序内部找到的文件具有以下配置:
{\n "extends": "../../../tsconfig.json", // Path to global tsconfig.json\n "compilerOptions": {\n "outDir": "js", // Where the transpiled Javascript files go\n "rootDir": "ts", // Where the Typescript files are\n },\n}\nRun Code Online (Sandbox Code Playgroud)\n然后,tsc -p App1/static/App1例如,当我运行时,App1\ 文件夹内的 Typescript 文件ts将被编译并放置在该文件夹内js。到目前为止一切都还好。
我知道它可能使用@font-face,但我不知道将我的 woff 文件放在哪里以让 Svelte 使用自定义字体。我也不知道把@font-face 放在哪里。提前致谢!
我尝试从 API 接受数据,然后使用 Pydantic 基础模型验证响应结构。但是,我遇到的情况是,有时某些字段不会包含在响应中,而有时会包含在响应中。问题是,当我尝试验证结构时,Pydantic 开始抱怨这些字段“丢失”,尽管它们有时可能会丢失。我真的不明白如何将一个字段定义为“missible”。文档提到仅定义为名称和类型的字段被认为是这种方式,但我没有任何运气
这是我想要实现的目标的一个简单示例
# Response: {a: 1, b: "abc", c: ["a", "b", "c"]}
response: dict = json.loads(request_response)
# Pydantic Base Model
from pydantic import BaseModel
class Model(BaseModel):
a: int
b: str
c: List[str]
d: float
# Validating
Model(**response)
# Return: ValidationError - Missing "d" field
Run Code Online (Sandbox Code Playgroud)
如何使“d”不会导致验证抛出错误?我尝试将“d”切换为d: Optional[float]和d: Optional[float] = 0.0,但没有任何作用。
谢谢!
deployment ×1
docker ×1
fonts ×1
linux ×1
pydantic ×1
python ×1
svelte ×1
tsconfig ×1
typescript ×1
typing ×1