-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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 with example settings #1495
Comments
Why do you say it is a bug? |
No, i upgraded from Ubuntu 18.04 to Ubuntu 20.04. It was running fine on Ubuntu 18.04. productive a long time like this. So it looks like the interfaces were changing? |
Is the program stopping here? Looks like it's only a warning but it's very straightforward about what's going on. |
@phy25 Yes it stops here. I was searching through a bit, and found this issue report on uvicorn under Windows. |
When I try it as supposed in the related issues, it gives me errors as well:
and
So uvicorn did not found the |
This is intended and not related to fastapi: https://github.com/encode/uvicorn/blob/9b92925a352b9743c5cfcef4a65e74a81a1bad4f/uvicorn/main.py#L343 You need to run it with command line |
The answer I was searching for is here: You can actually start it the way I wanted it, but make sure to name it correctly:
raises Error because the file is not named main.py! If you have it as
|
Adding another snippet as the ones posted here were pretty cryptic for me. With the following files:
I needed my import uvicorn
# Importing app here makes the syntax cleaner as it will be picked up by refactors
from app.main import app
if __name__ == "__main__":
uvicorn.run("debug_server:app", host="0.0.0.0", port=80, reload=True) That way the debug auto-reload server did work properly and there’s nothing related to it in the |
I got following error $ uvicorn main:app --reload I am using uvicorn [0.13.4] on Windows 10 Kindly suggest steps to resolve it. |
You can use pathlib to avoid this problem: from pathlib imprt Path
uvicorn.run(f"{Path(__file__).stem}:app", host='0.0.0.0', port=8127, workers=2) |
Try this. import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def get_root():
return {"message": "Hello World"}
if __name__ == "__main__":
uvicorn.run("__main__:app", host="0.0.0.0", port=8000, reload=True, workers=2) |
What also worked for me was this: inside the if __name__ == "__main__":
run(app="api:app", reload=True, port=8080, host="0.0.0.0") |
This depends on your file being named Further reading https://docs.python.org/3/library/__main__.html |
Thanks for reporting back and closing the issue @cgi1 ! 🍰 And thanks everyone else for the discussions here. ☕ |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
than it quits with SystemError 1
Corresponding ticket in uvicorn
Versions:
The text was updated successfully, but these errors were encountered: