Python Flask heroku application error

I think a likely possibility is that that gunicorn is not using the correct port. Heroku assigns a port for the application. I'm not entirely sure if that port gets assigned randomly or if it has a default. But if this is what is causing the problem, changing the Procfile to this should fix it:

web: gunicorn -b :$PORT app:app

This way catches whatever port assignment Heroku does. Or if you choose to set an environment variable for PORT it will also use that. gunicorn defaults to port 8000, so setting the PORT environment variable to 8000 on Heroku should also work.

  • Related: Deploying Flask app to Heroku

I'm pretty sure that the app.run does not effect the gunicorn server in any way. I think that gunicorn just finds the application instance in the module specified by app:app (module:appinstance), and loads the views.

  • ref: http://docs.gunicorn.org/en/stable/settings.html#bind