'Flask App Error while deploying to Heroku at=error code=H10 desc="App crashed" method=GET path="/"

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



Solution 1:[1]

Modified the Procfile as mentioned in the below post to

web: gunicorn --bind 0.0.0.0:$PORT flaskapp:app

Solution 2:[2]

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.

Solution 3:[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

Solution 4:[4]

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.

Solution 5:[5]

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

Solution 6:[6]

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

Solution 7:[7]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akhil Pakkath
Solution 2 Jordon Gonzales
Solution 3 Ashish Bharam
Solution 4 ppwater
Solution 5 Pratham Sarankar
Solution 6 Chirayu Asati
Solution 7 grey