Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uvicorn: Attribute "app" not found in module "app.app"

I’m a newbie. I’m trying to follow a basic guide to begin using FastAPI and uvicorn. However, I seem to be getting these errors, and I’m not sure why. I followed steps in the video, and wrote the same code(And file structure is the same, app.py in app folder, main.py in outer folder)

main.py

import uvicorn

if __name__ == "__main__":
    uvicorn.run("app.app:app", port=8000, reload=True)

app.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from fastapi import FastAPI
app = FastAPI()

@app.get("/", tags=['ROOT'])
async def root() -> dict:
    return{"Ping":"Pong"}

Launching main.py results in the following error:

Error loading ASGI app. Attribute "app" not found in module "app.app".

I tried moving code from app.py to a different file, and launching it directly from command line using uvicorn, but got the same error

>Solution :

You should start uvicorn with app:app. The file name is already declared in the first part of app:app.

import uvicorn

if __name__ == "__main__":
    uvicorn.run("app:app", port=8000, reload=True)

Also, you could run uvicorn from your terminal like so:

uvicorn app:app --port 8000 --reload
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading