SOLVED: Help needed! Flask App Deployment on Heroku

SOLVED: Help needed! Flask App Deployment on Heroku
0

Greetings,

Looking to get some help with deploying my Flask app on heroku. When I try to deploy I am getting the following error (using the heroku log --tails command)

at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=flasknoteapp.herokuapp.com request_id=8f13795b-41f3-4a35-b93b-8f97b98c32f5 fwd="71.235.184.204" dyno= connect= service= status=503 bytes= protocol=https

When deploying on heroku I am using gunicorn and with a Procfile, with the following script.

Procfile

web: gunicorn "flaskr:create_app()"

I can start up the application locally using the script in the procfile (without the β€œweb:”) in the terminal. I looked up the error code and it seems like an error in the procfile but I do not know what exactly. If anyone has some experience in this I would love some help.

Thanks,

Below is some information about how my project is structured, as I know the procfile script will depend on how the app is executed.


The structure of the application is exactly as the factory layout for flask, more specifically the flaskr set up for flask with SQLAlchemy.

Example of the project structure (so you don’t have to go through the link).

/home/user/Projects/flask-tutorial
β”œβ”€β”€ flaskr/
β”‚ β”œβ”€β”€ init.py
β”‚ β”œβ”€β”€ db.py
β”‚ β”œβ”€β”€ schema.sql
β”‚ β”œβ”€β”€ auth.py
β”‚ β”œβ”€β”€ blog.py
β”‚ β”œβ”€β”€ templates/
β”‚ β”‚ β”œβ”€β”€ base.html
β”‚ β”‚ β”œβ”€β”€ auth/
β”‚ β”‚ β”‚ β”œβ”€β”€ login.html
β”‚ β”‚ β”‚ └── register.html
β”‚ β”‚ └── blog/
β”‚ β”‚ β”œβ”€β”€ create.html
β”‚ β”‚ β”œβ”€β”€ index.html
β”‚ β”‚ └── update.html
β”‚ └── static/
β”‚ └── style.css
β”œβ”€β”€ tests/
β”‚ β”œβ”€β”€ conftest.py
β”‚ β”œβ”€β”€ data.sql
β”‚ β”œβ”€β”€ test_factory.py
β”‚ β”œβ”€β”€ test_db.py
β”‚ β”œβ”€β”€ test_auth.py
β”‚ └── test_blog.py
β”œβ”€β”€ venv/
β”œβ”€β”€ setup.py
└── MANIFEST.in

The application call is inside the init.py as a function called create_app() in the flaskr directory.

To run the application I set the following command,

$ export FLASK_APP=flaskr
$ export FLASK_ENV=development
$ flask init-db
$ flask run

I figured out the issue. Below are some high level instruction for future reference in case anyone else is interested:

Heroku doesn’t work too well with SQLite (at least the way I had the project structured it seemed). So I created a PostgreSQL Database inside the Heroku application via the follow command:

$ heroku addons:add heroku-postgresql:hobby-dev

With the new PostgreSQL database you’ll need a few dependent library so that it works with the SQLite database that is in the web application. More specifically you’ll need psycopg2, but before you get psycopg2 you’ll need a few other things as well.

sudo apt install gcc
sudo apt install libpq-dev
sudo apt install psycopg2

I would recommend you take a look at the documentation for full details on installing psycopg2 as it was a bit more involved for my system.

See details at https://www.psycopg.org/docs/install.html

Now you just need to update the requirement text file with the new packages, just run.

Update requirements:

(venv) $ pip freeze > requirements.txt

Finally set the flask app path to the run Heroku flask_app command.

$ heroku config:set FLASK_APP=flaskr
1 Like