【问题标题】:Deploy Python Flask App to Heroku R10 Error将 Python Flask 应用程序部署到 Heroku R10 错误
【发布时间】:2018-04-07 04:28:39
【问题描述】:

我希望使用免费的 dyno 将烧瓶应用程序部署到 Heroku,它似乎构建成功:

remote: Git submodules detected, installing:
remote: 
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 83.2M
remote: -----> Launching...
remote:        Released v94
remote:        https://MYAPP.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.

然后在访问 URL 后检查 Heroku 日志,我抛出了这个错误:

2017-10-25T22:33:09.264449+00:00 heroku[web.1]: Starting process with command `python run.py runserver`
2017-10-25T22:33:15.514250+00:00 app[web.1]:  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2017-10-25T22:33:15.519730+00:00 app[web.1]:  * Restarting with stat
2017-10-25T22:33:17.300082+00:00 app[web.1]:  * Debugger is active!
2017-10-25T22:33:17.305442+00:00 app[web.1]:  * Debugger pin code: 146-142-273
2017-10-25T22:34:09.286891+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-10-25T22:34:09.286934+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-10-25T22:34:09.469418+00:00 heroku[web.1]: Process exited with status 137
2017-10-25T22:34:09.484569+00:00 heroku[web.1]: State changed from starting to crashed

在各种帮助站点中遇到此问题的所有其他人在绑定到 Heroku $PORT 时都解决了他们的问题,与我的做法相同:

#!venv/bin/python
import os
from app import app
port = int(os.environ.get('PORT', 33507))
app.run(host='0.0.0.0', port=port, debug=False)

还有我的Procfile

web: python run.py runserver

会不会是我在运行虚拟环境?也许我的 83.2M 应用程序太大了?我有点卡在这里。提前感谢您的帮助!

【问题讨论】:

  • 你检查过是否有任何测功机正在运行吗?
  • 我确实尝试过检查,但这不是问题的一部分吗?我启动测功机,稍等片刻,然后读入日志Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
  • 试试port = int(os.environ.get('PORT', 5000))。参考stackoverflow.com/a/13714363/4410922
  • 已经试过没有成功
  • web: python ./run.py替换Procfile

标签: python python-3.x heroku flask


【解决方案1】:

尝试像这样更改您的 Procfile 内容:

web: gunicorn run:app -b "0.0.0.0:$PORT" -w 3

其中run 是主应用程序文件的名称,表示run.py

【讨论】:

  • -w 3 为我修复了它。你能解释一下-w 3 的作用吗?
  • 刚刚意识到 -w 3 意味着 3 个工人。我想知道为什么会修复它。
【解决方案2】:

尝试改变:

  • Procfile 内容应该是:

    web: python run.py
    
  • 端口号从 33507 到 8080

  • 调试 = 真。

【讨论】:

    猜你喜欢
    • 2016-04-15
    • 2012-11-22
    • 2019-01-29
    • 1970-01-01
    • 2020-04-09
    • 2022-06-30
    • 1970-01-01
    相关资源
    最近更新 更多