I'm trying to deploy a Python FastAPI server as a web service on Render, but I encounter the following error in the logs after deployment:
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [86] using WatchFiles
==> No open ports detected on 0.0.0.0, continuing to scan...
INFO: Started server process [88]
INFO: Waiting for application startup.
INFO: Application startup complete.
This results in a message stating "no open ports detected". I've tried changing the port to 8000 and several others but can't seem to resolve the issue.
What I've tried: Ensuring the uvicorn.run() method uses 0.0.0.0 as the host to bind to all interfaces:
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="debug")
Setting the port dynamically to use the PORT environment variable provided by Render with a default fallback:
port = int(os.environ.get("PORT", 8000))
uvicorn.run(app, host="0.0.0.0", port=port, log_level="debug")
Additional Information:
The application runs fine locally.
I've checked the Render documentation on web service port binding and followed the guidelines.
Could there be a configuration step I'm missing, or is there something specific about Render's environment that I need to adjust?
The default value of PORT is 10000 for all Render web services.
Try use start command ti run application
uvicorn main:app --host 0.0.0.0 --port $PORT
Check this links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With