fastapi + uvicorn 出现 Fetch error Not Found openapi.json

from fastapi import FastAPI

app = FastAPI()

@app.get('/')

async def root():

return {"message": "Hello World"}

启动命令:uvicorn api:app --host '0.0.0.0' --port 63000 --workers 1 --root-path=/api/v1

使用了 --root-path=/api/v1 就会导致找不到 openapi.json

fastapi + uvicorn  出现  Fetch error Not Found openapi.json

(test_nameko_for_rabbitmq) ╭─bot@mbp13m1.local ~/Desktop/code/test_nameko_for_rabbitmq  ‹master*› 

╰─➤ uvicorn api:app --host '0.0.0.0' --port 63000 --workers 1 --root-path=/api/v1

INFO: Started server process [52977]

INFO: Waiting for application startup.

INFO: Application startup complete.

INFO: Uvicorn running on http://0.0.0.0:63000 (Press CTRL+C to quit)

INFO: 127.0.0.1:58301 - "GET /api/v1/docs HTTP/1.1" 200 OK

INFO: 127.0.0.1:58301 - "GET /api/v1/api/v1/openapi.json HTTP/1.1" 404 Not Found

fastapi + uvicorn  出现  Fetch error Not Found openapi.json


回答:

最后的解决方案就是不用 --root-path

一开始为什么要用 --root-path

是因为有人搞了一个 nginx 转发。。。

但是 nginx 转发的时候是可以让 nginx 去掉前缀问题的,也就是说这个问题应该从 nginx 的角度解决

而不是让 fastapi 和 uvicorn 加 --root-path 这种丑陋的东西

以上是 fastapi + uvicorn 出现 Fetch error Not Found openapi.json 的全部内容, 来源链接: utcz.com/p/938216.html

回到顶部