-
than it quits with SystemError 1 Corresponding ticket in uvicorn Versions: |
Beta Was this translation helpful? Give feedback.
Replies: 17 comments 1 reply
-
|
Why do you say it is a bug? |
Beta Was this translation helpful? Give feedback.
-
|
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? |
Beta Was this translation helpful? Give feedback.
-
Is the program stopping here? Looks like it's only a warning but it's very straightforward about what's going on. |
Beta Was this translation helpful? Give feedback.
-
|
@phy25 Yes it stops here. I was searching through a bit, and found this issue report on uvicorn under Windows. |
Beta Was this translation helpful? Give feedback.
-
|
When I try it as supposed in the related issues, it gives me errors as well: and So uvicorn did not found the |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here @phy25 ! 👏 🙇 If that solves the original problem, then you can close this issue @cgi1 ✔️ |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
I got following error $ uvicorn main:app --reload I am using uvicorn [0.13.4] on Windows 10 Kindly suggest steps to resolve it. |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
|
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) |
Beta Was this translation helpful? Give feedback.
-
|
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") |
Beta Was this translation helpful? Give feedback.
-
This depends on your file being named Further reading https://docs.python.org/3/library/__main__.html |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for reporting back and closing the issue @cgi1 ! 🍰 And thanks everyone else for the discussions here. ☕ |
Beta Was this translation helpful? Give feedback.
-
|
Try
This works and fixes the issue |
Beta Was this translation helpful? Give feedback.
-
|
Note: Then using Que: |
Beta Was this translation helpful? Give feedback.
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
my_fastapi_server.py, you run it as follows: