question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}

Description

I was trying th basic code given on fastapi to verify my FASTAPI installation. I tried to execute above code with following command ‘uvicorn main:app --reload’ but got the bellow error

INFO: Will watch for changes in these directories: [‘D:\FASTAPI’] INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [7900] using watchgod ERROR: Error loading ASGI app. Attribute “app” not found in module “main”.

Operating System

Windows

Operating System Details

windows 10

FastAPI Version

0.70.0

Python Version

3.9.6

Additional Context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
akitibalacommented, Nov 16, 2021

hi @sudoalger , please use uvicorn src.main:app instead of uvicorn src.main::app

0reactions
oligondcommented, Dec 16, 2022

I didn’t include extra code to keep the example clean.

That’s a good intention, but in your case (as I see it), the crucial parts people have to see in order to give useful advice how to solve your problem are missing.

Again, this looks like a problem of code organisation (how to avoid the circular import). Actually, I think you can build in the example from the fastapi-socketio docs: Just move the declaration of the socket handlers into a separate module and mount the socket manager in your app in main.py.

So

  • please create a new issue (and link there from here)
  • add the code portion to your example which is creating and mounting the socketio server to your app

and I’m pretty sure you will get the advice you need in no time

Read more comments on GitHub >

github_iconTop Results From Across the Web

FastAPI throws an error (Error loading ASGI app. Could not ...
Could not import module "main". The answer is so simple, add the folder name in front of your filename uvicorn src.main:app --reload.
Read more >
FastAPI Error loading ASGI app. Could not import module 'main'
The FastAPI Error loading ASGI app. Could not import module 'main' occurs when your terminal is located in a directory that doesn't contain...
Read more >
Error loading ASGI app. Could not import module "main"
Install the software on Ubuntu, accidentally upgrade PIP, resulting in the use Times as follows: Later, it was found that this problem was...
Read more >
tiangolo/fastapi - Gitter
Hello there, if the main script of my app has not '.py' extension, I have the next error: ERROR: Error loading ASGI app....
Read more >
Settings - Uvicorn
Also note that UVICORN_* prefixed settings cannot be used from within an ... APP - The ASGI application to run, in the format...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found