Uvicorn can not start FastAPI APP

See original GitHub issue
import uvicorn
from fastapi import FastAPI
app = FastAPI(title='MADS API')
uvicorn.run(app, host='0.0.0.0', port=8127, workers=2)
WARNING:  You must pass the application as an import string to enable 'reload' or 'workers'.

(Than it quits with System Code 1)

Versions:

$ pip3 list |grep "uvicorn\|fastapi"
fastapi                          0.55.1       
uvicorn                          0.11.5 

Ubuntu 20.04; python 3.8.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
dhendocommented, Jun 1, 2020

It’ll depend on the file name - if for example it was called server.py then the string you should use is "server:app"

2reactions
dhendocommented, May 29, 2020

I think you need to pass the app as a string, rather than directly, as you’ve passed the workers argument.

uvicorn.run("your_module_name:app", host='0.0.0.0', port=8127, workers=2)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] uvicorn can not start FastAPI with example settings #1495
You must pass the application as an import string to enable 'reload' or 'workers'. Is the program stopping here? Looks like it's only...
Read more >
FastAPI throws an error (Error loading ASGI app. Could not ...
I encountered this issue because I mistakenly added .py in the command like this uvicorn main.py:app . It should be uvicorn main:app ....
Read more >
Run a Server Manually - Uvicorn - FastAPI
The main thing you need to run a FastAPI application in a remote server machine is an ASGI server program like Uvicorn. There...
Read more >
Error loading ASGI app. Could not import module "main"
One reason this might be happening is that you are using: uvicorn src ... I am trying to start a FastAPI app but...
Read more >
Deployment - Uvicorn
Run uvicorn --reload from the command line for local development. ... The ASGI application should be specified in the form path.to.module:instance.path .
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