【问题标题】:FastAPI keeps throwing an error loading (ASGI app)FastAPI 不断抛出错误加载(ASGI 应用程序)
【发布时间】:2021-10-24 10:24:04
【问题描述】:

文件名是 ma​​in.py 每当我运行uvicorn main:app --reload 我在代码下得到错误。

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

错误

INFO:     Will watch for changes in these directories: ['/Users/Documents/main.py']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [58745] using statreload
ERROR:    Error loading ASGI app. Could not import module "main".

【问题讨论】:

    标签: python command-line frameworks fastapi


    【解决方案1】:

    检查你的文件名是否应该是 main 或者如果那个名字是'example'你应该写:uvicorn example:app --reload

    【讨论】:

      【解决方案2】:

      您是否在与文件 main.py 相同的目录中运行命令 uvicorn main:app --reload ?可能这就是你的问题。 我测试了你的代码,它对我有用。

      【讨论】:

        猜你喜欢
        • 2020-07-04
        • 2022-01-20
        • 1970-01-01
        • 2016-10-05
        • 1970-01-01
        • 1970-01-01
        • 2014-07-11
        • 2021-02-09
        • 1970-01-01
        相关资源
        最近更新 更多