9

The sample flask app is giving error at=error code=H10 desc="App crashed" method=GET path="/" while deploying in Heroku.

Flaskapp.py

from flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
    return "<h1> Deployed to Heroku</h1>"


if __name__ == "__main__":
    app.run()'''

Pocfile

web : gunicorn flaskapp:app

requirements.txt

Click==7.0
Flask==1.1.1
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
Werkzeug==0.16.0

error log below

2020-01-10T10:35:14.658092+00:00 heroku[web.1]: Starting process with command `: gunicorn flaskapp:app`
2020-01-10T10:35:16.404755+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-10T10:35:16.381754+00:00 heroku[web.1]: Process exited with status 0
2020-01-10T10:35:19.000000+00:00 app[api]: Build succeeded
2020-01-10T10:35:38.654704+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=flaskapp-te.herokuapp.com request_id=6712472d-a734-4720-b152-1e2716844c41 fwd="137.97.4.98" dyno= connect= service= status=503 bytes= protocol=https
2020-01-10T10:35:39.689766+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=flaskapp-te.herokuapp.com request_id=89a26803-5b09-4a94-99a2-5b0d154d7797 fwd="137.97.4.98" dyno= connect= service= status=503 bytes= protocol=https

followed some blogs and couldnt solve. Please assist

VC.One
  • 14,790
  • 4
  • 25
  • 57
Akhil Pakkath
  • 283
  • 1
  • 5
  • 14

8 Answers8

10

Modified the Procfile as mentioned in the below post to

web: gunicorn --bind 0.0.0.0:$PORT flaskapp:app
Akhil Pakkath
  • 283
  • 1
  • 5
  • 14
  • Hi, I am same issue even though I added bind port in Procfile.. The app still crashes.. Can u tell me why is it happening? –  May 20 '21 at 19:46
3

1 year and 2 months later. As the other answers pointed out, there is a an issue in the Procfile. I personally don't think the --bind 0.0.0.0:$PORT is needed as my apps have run fine with out that portion of code - but I don't pretend to know what its purpose is. For this particular issue, the space in the Procfile is the issue and I found this tutorial helpful when addressing my own Procfile issues.

However, I wanted to add the following for those finding this while knowing their Procfile isn't the issue but are still getting the h10 error.

For those finding this specifically for h10 error, and you know your Procfile is correct, make sure you are reading the full logs. I found that hidden in the mess were lines stating that certain modules were not found. Apparently my pip installs were incomplete or not in my virtual env folder. And not all missing installations will show up. Each push may present new modules that need to be installed and added to your requirements.txt file. Took several pushes to work through each missing item and eventually my app began to run correctly on Heroku.

Jordon Gonzales
  • 171
  • 1
  • 7
  • 1
    For an hour I was searching, but didn't find any solutions. I didn't pay attention to this answer because it had no votes, but I used the tutorial that you included and now my flask app works like a charm. thanks! – gha7all Mar 30 '22 at 18:06
3

My Project Structure

My Project Structure Create file named Procfile (extension not required) - write a following line into it web: gunicorn main:app where "main" is the file name in which app = create_app() is mentioned

pip install gunicorn

pip freeze > requirements.txt

create one more file named runtime.txt which contains following line python-3.9.2 (provide respective python version of your project)

Heroku Part: run following commands one by one using gitbash or vscode console

heroku login

git init

git add .

git commit -am "Initial Commit"

git push heroku main

Ashish Bharam
  • 201
  • 1
  • 3
  • 8
0

You have the bug in your procfile.

web: gunicorn

It should be written like this. Don't give a space after web and it will work fine.

ppwater
  • 2,315
  • 4
  • 15
  • 29
0

I got the same error, compared to the last time you might have installed some new packages in pip and imported them in your app.py file. Just regenerate your requirements.txt file and again push it to heroku master, it will run fine

1> Open your terminal

2> type - cd YOUR_PROJECT_DIRECTORY

3> type - pip freeze > requirements.txt

4> push your code to the your repository.

5> git push heroku master

Pratham Sarankar
  • 555
  • 6
  • 10
0

Make sure gunicorn is included in the requirements.txt file.

0

In proc file web: gunicorn --bind 0.0.0.0:$PORT app:app Confirm in app if name == 'main': app.run(debug=True)

grey
  • 209
  • 3
  • 6
0

Apart from the above solutions, I found one other issue with my setup. Make sure your requirements.txt file has everything what you need.

When you open your heroku app page, look for the heroku logs (type heroku logs --tail in terminal), if it shows error H10 wait for few minutes, dont close your terminal (if you are looking the logs in terminal).

After few minute it shows certain other errors, in my case it shows Import error for opencv. Instead of having opencv-python in my requirements page, I changed it to opencv-contrib-python-headless in the requirements.txt file (refer this page)

In a nutshell, make sure your requirements.txt is proper, especially while using packages like opencv