"Permission Denied" when trying to deploy FastAPI app using Uvicorn

Hello, I have been trying to deploy a FastAPI app to Render using uvicorn but I’m constantly running into errors.

When I first built my app using pip install -r requirements.txt and started it using Gunicorn:
cd app && gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app,
the app never showed any errors but did not load after going to the site.

I then came across the thread about deploying with uvicorn and realising it was not on the same port, I used the same command but to no avail. It shows me these errors in the logs now:

Nov 23 12:11:39 PM  ==> Starting service with 'cd app && uvicorn main:app --host 0.0.0.0 --port 80'
Nov 23 12:11:42 PM  INFO:     Started server process [48]
Nov 23 12:11:42 PM  INFO:     Waiting for application startup.
Nov 23 12:11:42 PM  INFO:     Application startup complete.
Nov 23 12:11:42 PM  ERROR:    [Errno 13] error while attempting to bind on address ('0.0.0.0', 80): permission denied
Nov 23 12:11:42 PM  INFO:     Waiting for application shutdown.
Nov 23 12:11:42 PM  INFO:     Application shutdown complete.

Can someone please help me out?

Thanks in advance!

Try by not specifying port see if it takes a default port assigned by render

Thanks for the reply!
There are no errors now, but it’s still not loading. I get a blank page.

The deploy is stuck too. Its still showing in progress....

Nov 23 12:49:56 PM  INFO:     Started server process [70]
Nov 23 12:49:56 PM  INFO:     Waiting for application startup.
Nov 23 12:49:56 PM  INFO:     Application startup complete.
Nov 23 12:49:56 PM  INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

Just an update- I deleted the service, created a new one from scratch and it worked!

Though I’m not sure why.

I have another question: Why do the builds take so long to deploy and then show that the deploy has failed?
from the logs I have shown below, the build seems to have completed properly and the service has been started, but it just gets stuck at in progress... and then eventually fails.

...
Nov 23 02:27:56 PM   ==> Uploading build...
Nov 23 02:28:49 PM   ==> Build successful 🎉
Nov 23 02:28:49 PM   ==> Deploying...
Nov 23 02:29:10 PM  ==> Starting service with 'cd app && gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0'
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [48] [INFO] Starting gunicorn 20.1.0
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [48] [INFO] Listening at: http://0.0.0.0:8000 (48)
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [48] [INFO] Using worker: uvicorn.workers.UvicornWorker
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [51] [INFO] Booting worker with pid: 51
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [52] [INFO] Booting worker with pid: 52
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [53] [INFO] Booting worker with pid: 53
Nov 23 02:29:14 PM  [2021-11-23 08:59:14 +0000] [54] [INFO] Booting worker with pid: 54
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [52] [INFO] Started server process [52]
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [52] [INFO] Waiting for application startup.
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [52] [INFO] Application startup complete.
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [53] [INFO] Started server process [53]
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [53] [INFO] Waiting for application startup.
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [53] [INFO] Application startup complete.
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [51] [INFO] Started server process [51]
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [51] [INFO] Waiting for application startup.
Nov 23 02:29:15 PM  [2021-11-23 08:59:15 +0000] [51] [INFO] Application startup complete.
Nov 23 02:29:16 PM  [2021-11-23 08:59:16 +0000] [54] [INFO] Started server process [54]
Nov 23 02:29:16 PM  [2021-11-23 08:59:16 +0000] [54] [INFO] Waiting for application startup.
Nov 23 02:29:16 PM  [2021-11-23 08:59:16 +0000] [54] [INFO] Application startup complete.

These are the last few lines of logs before the deploy fails.

EDIT: I managed to fix that too!

I had an environment variable PORT that had a different value than what was expected. It had to match the port the server was listening on. (taken from this thread)