flask-boilerplate: Deploying app on Heroku (code=H10 desc="App crashed")

Hello, I followed the steps in your README file to clone the repo and deploy the app on Heroku. I immediately got the following errors when opening the website: Gist

Here’s is the history of what I did exactly:

git clone https://github.com/mjhea0/flask-boilerplate.git
cd flask-boilerplate
virtualenv --no-site-packages env
source env/bin/activate
pip install -r requirements.txt
python app.py
heroku login
heroku create
git push heroku master
heroku open

The app is running properly on localhost. Did I miss something? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 6
  • Comments: 73 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I figured out that I have to use web: gunicorn app:app --log-file=- in the Procfile.

where? in Procfile?

I’d be interested in knowing the solution for this. I build a node app, using reactJS. when i deployed to Heroku, i got the similar issue. I think it has to do with the asset thing. Can anyone explain me how to solve this problem?

Set the PORT numbers dynamically rather than a hardcoded value

The issue is Heroku will provide a port number for your app. But if you have hardcoded the port numbers in your code then there will conflict b/w assigned and usage port. So, if it is running on another port, if you fetching file(ie favicon or ‘/’) from another port it crashes with an error of H10.

FIX: If in node.js try process.env.PORT which fetches the assigned port number. For flask, python : port = int(os.environ.get('PORT', 5000)) This dynamically fetches port number and sets it. If not uses 5000. Solved the problem for me. If not there could be another issue but typically this is the fix.

Other possible error

The Heroku app need gunicorn to interface with your app. So, create a Profile without any extension and add the code as @nop33 has mentioned on the thread. Be sure to double check the name of your app and name mentioned in the Procfile. Because the Procfile gives Heroku the information to run your app

I found two possible solutions:

  1. try adding “gunicorn” to your requirements.txt file.
  2. make your Procfile like this: web: gunicorn <application-name>.wsgi --log-file -

THIS SOLUTION IS FOR GO When you deploy an app through heroku, it does not allow you to specify the port number.
In other words, you can not specify your web service’s port number as 8000 or something else, heroku decides the port number in runtime.
so, you can not use the following code:

    log.Fatal(http.ListenAndServe(":8000", router))

What you can do is, getting the runtime port of heroku.
In short, just use the following code:

    log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))

Heyy, Check your procfile and make sure all your dependencies are well set.

On Fri, 12 Nov 2021, 23:38 Matt, @.***> wrote:

Hi, hope this is still usefull and on topic, but I have been struggling also with this app crashed issue using Flask to deploy my API. I am also new to Heroku so I had not much clue of what I was doing. But check well the result of the “heroku logs --tail”. What happened in my case was that there was nothing wrong with ports, Procfile, requirements or that kind of things. The code I had to deal with the data the API was handling WAS WRONG. So that is why it was crushing, once fixed everything worked fine.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/realpython/flask-boilerplate/issues/14#issuecomment-967706500, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOIAFHY7RSIHQ7SWQVFG5R3ULWJOXANCNFSM4BEZTEEA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

I’m having the same problem with a flask project. Runs locally, but crashes when I deploy to Heroku.

Error: 2020-02-04T07:37:29.181357+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path=“/” host=criticancia.herokuapp.com request_id=13282857-17e5-4639-80ed-025d992e5058 fwd=“189.40.102.107” dyno= connect= service= status=503 bytes= protocol=https 2020-02-04T07:37:29.683718+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path=“/favicon.ico” host=criticancia.herokuapp.com request_id=d34ac233-d2ba-4abb-b742-0918c9f56fe2 fwd=“189.40.102.107” dyno= connect= service= status=503 bytes= protocol=https

I’m not sure if this applies to any of you but might help someone out. My Procfile was like this web gunicorn app:app but my requirements.txt did not include gunicorn as I had not been using it when testing it locally. Once I added it to my requirements everything was fine

Another solution:

Check if your application has ‘gunicorn’ installed with pip freeze, if not, run the command pip install gunicorn.

After that, run pip freeze > requirements.txt

With that it will create a file with the current requirements of your application, note that ‘gunicorn’ will be in it.

@PraveenAsh I’m having the same problem with a flask app. Where am I supposed to add that python code you mentioned? In my app.py file? If so, where exactly in the app.py file? Thanks