Heroku App立即崩溃,并出现R10和H10错误


问题内容

我的应用程序可以使用foreman run在本地运行良好,而当我runserver.py使用来执行文件时,则可以正常运行python runserver.py。当我将其推到Heroku时,它崩溃了。我什至对我的procfile进行了更改:web: python runserver.py ${PORT}这样Heroku可以绑定到端口号,但无济于事…我已经有将近3天的时间了。首先是我的Procfile,现在是Heroku
…任何帮助将不胜感激。此外,我在该项目的Flask框架中使用了Python-我遇到了Heroku,但它似乎仅适用于RoR应用程序。

2014-02-24T02:24:50.146153+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
    2014-02-24T02:24:51.323561+00:00 heroku[web.1]: Process exited with status 137
    2014-02-24T02:24:51.333621+00:00 heroku[web.1]: State changed from starting to crashed
    2014-02-24T02:24:51.334368+00:00 heroku[web.1]: State changed from crashed to starting
    2014-02-24T02:24:55.793531+00:00 heroku[web.1]: Starting process with command `python runserver.py`
    2014-02-24T02:24:57.117683+00:00 app[web.1]:  * Running on http://127.0.0.1:5000/
    2014-02-24T02:24:57.117683+00:00 app[web.1]:  * Restarting with reloader
    2014-02-24T02:23:43.987388+00:00 heroku[api]: Deploy c55f7b6 by shaunktw@gmail.com
    2014-02-24T02:23:43.987478+00:00 heroku[api]: Release v8 created by shaunktw@gmail.com
    2014-02-24T02:25:56.204701+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
    2014-02-24T02:25:56.204929+00:00 heroku[web.1]: Stopping process with SIGKILL
    2014-02-24T02:25:57.495657+00:00 heroku[web.1]: Process exited with status 137

程序文件:

web: python runserver.py ${PORT}

runserver.py:

from intro_to_flask import app

app.run(debug=True)

问题答案:

我找到了这个问题的答案…本质上,我必须绑定端口并指定正在使用的主机:

在我的runserver.py文件中,我使用以下命令对其进行了修改:

import os
from intro_to_flask import app

port = int(os.environ.get("PORT", 5000))
app.run(debug=True, host='0.0.0.0', port=port)

这可能不是最优雅的方法,但它确实有效。