Web进程在启动后60秒内无法绑定到$ PORT

时间:2016-04-18 00:03:52

标签: python heroku flask

有人可以在Heroku上向我解释此错误消息吗?应用程序在本地运行良好但从未在线成功

heroku[slug-compiler]: Slug compilation started
heroku[slug-compiler]: Slug compilation finished
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `python app.py ${PORT}`
app[web.1]:  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

应用程序本身并不复杂

from flask import Flask, render_template
app = Flask(__name__, static_folder='static') 

@app.route('/')
def hello_world():
    return render_template('index.html')

if __name__ == '__main__':
    from os import environ
    app.run(debug=False, port=environ.get("PORT", 5000))

1 个答案:

答案 0 :(得分:16)

您需要在host='0.0.0.0'中指定app.run()。除非另有说明,Flask绑定到“localhost”,这意味着它不会绑定到外部可见的界面。

请参阅Flask - configure dev server to be visible across the network