Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uvicorn can not start FastAPI APP #687

Closed
cgi1 opened this issue May 28, 2020 · 5 comments
Closed

Uvicorn can not start FastAPI APP #687

cgi1 opened this issue May 28, 2020 · 5 comments

Comments

@cgi1
Copy link

cgi1 commented May 28, 2020

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

@dhendo
Copy link

dhendo commented 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)

@euri10
Copy link
Member

euri10 commented May 29, 2020

yes @dhendo is right !

@euri10 euri10 closed this as completed May 29, 2020
@cgi1
Copy link
Author

cgi1 commented Jun 1, 2020

Understand - But how can I define the name of the module here`?

Uvicorn can not find your_module_name:

ERROR: Error loading ASGI app. Could not import module "your_module_name".

@dhendo
Copy link

dhendo commented 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"

@cgi1
Copy link
Author

cgi1 commented Jun 13, 2020

@dhendo This finally solved my issue - Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants