9

Can someone explain to me this error message on Heroku? App works fine locally but has never succeeded online

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

The app itself is not very complicated

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))
john mangual
  • 7,718
  • 13
  • 56
  • 95

1 Answers1

25

You need to specify host='0.0.0.0' in app.run(). Unless told otherwise, Flask binds to "localhost", which means it won't bind to an externally visible interface.

See Flask - configure dev server to be visible across the network

Community
  • 1
  • 1
bimsapi
  • 4,985
  • 2
  • 19
  • 27
  • Deployed a pure Python server (http.server.HTTPServer) to Heroku, it also works! `0.0.0.0` instead of the usual `localhost` does the trick, thanks @bimsapi! – kit May 19 '16 at 09:25
  • 1
    Saved me! thaks – rodrigorf Apr 27 '17 at 00:01
  • Glad to know that this is a flask API specification, and not a problem with Heroku (or any other hosting provider for that matter) – rageandqq Jul 07 '17 at 20:41