FastAPI keeps throwing an error loading (ASGI app)
Question:
the file name is main.py anytime i run uvicorn main:app --reload
i get the error under the code.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
Error
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".
Answers:
Are you running the command uvicorn main:app –reload in the same directory as the file main.py is? Probably that’s your problem.
I tested your code and it is working for me.
check that the name of your file should be main or if that’s name is ‘example’ you shuld write: uvicorn example:app –reload
the file name is main.py anytime i run uvicorn main:app --reload
i get the error under the code.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
Error
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".
Are you running the command uvicorn main:app –reload in the same directory as the file main.py is? Probably that’s your problem.
I tested your code and it is working for me.
check that the name of your file should be main or if that’s name is ‘example’ you shuld write: uvicorn example:app –reload