简体   繁体   English

Heroku 部署 Fastapi (Python) 在 uvicorn 上运行:Web process failed to bind to $PORT

[英]Heroku deployment of Fastapi (Python) running on uvicorn: Web process failed to bind to $PORT

We have a python 3.9 fastapi server that we are trying to get running on uvicorn on heroku.我们有一个 python 3.9 fastapi 服务器,我们正试图在 heroku 上的 uvicorn 上运行它。 It comes up fine when we start it on a heroku run bash instance but when it launches normally on the dyno manifold the port doesn't bind.当我们在heroku run bash实例上启动它时,它运行良好,但是当它在测功机歧管上正常启动时,端口不会绑定。

heroku/web.1 Starting process with command `uvicorn app.main:app --workers 4 --port 42374`
app/web.1 INFO:     Uvicorn running on http://127.0.0.1:42374 (Press CTRL+C to quit)
app/web.1 INFO:     Started parent process [4]
app/web.1 INFO:     Started server process [13]
app/web.1 INFO:     Waiting for application startup.
app/web.1 INFO:     Started server process [10]
app/web.1 INFO:     Waiting for application startup.
app/web.1 INFO:     Started server process [12]
app/web.1 INFO:     Waiting for application startup.
app/web.1 INFO:     Started server process [11]
app/web.1 INFO:     Waiting for application startup.
app/web.1 INFO:     Application startup complete.
app/web.1 INFO:     Application startup complete.
app/web.1 INFO:     Application startup complete.
app/web.1 INFO:     Application startup complete.
heroku/web.1 Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
heroku/web.1 Stopping process with SIGKILL
heroku/web.1 Process exited with status 137
heroku/web.1 State changed from starting to crashed

If I run it locally using Heroku CLI:如果我使用 Heroku CLI 在本地运行它:

root@d2258955b223:/workspaces/app-service-cross-sell# heroku run bash
Running bash on ⬢ aci-sell-service... up, run.4472 (Hobby)
~ $ uvicorn app.main:app --workers 4 --port $PORT
INFO:     Uvicorn running on http://127.0.0.1:26281 (Press CTRL+C to quit)
INFO:     Started parent process [141]
INFO:     Started server process [144]
INFO:     Waiting for application startup.
INFO:     Started server process [145]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Application startup complete.
INFO:     Started server process [143]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Started server process [146]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
^Z
[1]+  Stopped                 uvicorn app.main:app --workers 4 --port $PORT
~ $ bg
[1]+ uvicorn app.main:app --workers 4 --port $PORT &
~ $ curl http://localhost:26281
INFO:     127.0.0.1:55674 - "GET / HTTP/1.1" 200 OK

App loads from:应用程序从以下位置加载:

if __name__ == "__main__":
    uvicorn.run(
        "main:app",
        host="0.0.0.0",
        port=config.PORT,
        reload=not config.DEBUG,
        debug=config.DEBUG,
        log_level=VLabLogger.get_log_level_based_on_env().lower(),
    )

I would suggest creating a Procfile having:我建议创建一个具有以下内容的 Procfile:

web: uvicorn main:app --host=0.0.0.0 --port=${PORT}

and let heroku handle the PORT.并让 heroku 处理 PORT。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 python 部署到 Heroku - Web 进程无法绑定到 $PORT - Deploying python to Heroku - Web process failed to bind to $PORT Heroku Python Web进程在60秒内未能绑定到$ PORT-并不明显 - Heroku Python Web process failed to bind to $PORT within 60 seconds - not the obvious Heroku:错误R10(引导超时)-> Web进程在启动后60秒内未能绑定到$ PORT-Python - Heroku: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch - Python Heroku错误R10(引导超时) - > Web进程在启动后60秒内无法绑定到$ PORT - Heroku Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch python - 错误R10(引导超时) - > Web进程在启动后60秒内无法绑定到$ PORT - python - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 尝试将Python /烧瓶应用程序部署到Heroku时无法绑定到$ PORT - Failed to bind to $PORT when trying to deploy Python/flask app to Heroku Web进程在启动后60秒内无法绑定到$ PORT - Web process failed to bind to $PORT within 60 seconds of launch “没有 web 进程正在运行”Heroku 上的错误,部署 Fastapi - "No web processes running" Error on Heroku , Deploying Fastapi Heroku - 没有正在运行的Web进程 - Heroku - No web process running 在 python 上获取“错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定到 $PORT” - Getting "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch" on python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM