Flask app giving "Application Error" when hosted on Heroku

Issue

Just a precursor, I’ve looked at very similar questions on Stack Overflow and tried all the solutions suggested there however none of them worked so I’m assuming it’s something else I’m not getting. Also for various reasons I’m restricted to working exclusively online, and I can’t use any CLI commands I can only use the website as an interface.

I’ve been building a web-app with Flask (it works fine on repl.it), and I went to try host it on Heroku (connected through GitHub) but keep getting an "Application Error" when it loads with these two items in the log:

2022-08-09T08:48:18.336638+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=heroku-learning-temporary.herokuapp.com request_id=395ddf03-0a6e-4656-a185-09d6258ecfa9 fwd="124.171.47.188,165.225.114.89" dyno= connect= service= status=503 bytes= protocol=https
2022-08-09T08:48:19.449634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=heroku-learning-temporary.herokuapp.com request_id=95dc333b-3e5c-46bf-867d-d8444ac3d35a fwd="124.171.47.188,165.225.114.89" dyno= connect= service= status=503 bytes= protocol=https

So I built a really simple Flask app just to try identify the problem but got the exact same error logs. The really simple flask app I built looked like this:

app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
  return("Hello there")
 
 if __name__ == "__main__":
  app.run(port=5000)

wgsi.py

from app import app

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

requirements.txt

Flask==2.0
gunicorn==20.1.0

and Procfile

web: gunicorn wsgi:app

All of these are from the tutorial here with the exception of the requirements.txt which I added ’cause otherwise it failed in the build stage.

Is there something I’m not doing right? Or is it going wrong ’cause I’m not using the CLI but just using the website?

Also if it’s easier to view the code on GitHub my repository is here.

Solution

change your procfile to:
web: gunicorn app:app
your wsgi.py file can be deleted

Answered By – Fran Camacho

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published