Reputation: 581
My app keeps crashing on Heroku but works fine locally and on PythonAnywhere.
My Procile looks like this:
web: gunicorn wsgi:app
Inside the wsgi.py file I have added:
from app import create_app
app = create_app()
My init.py file is located within a folder called "app"
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
migrate.init_app(app, db)
bootstrap.init_app(app)
from app.main.routes import main
app.register_blueprint(main)
return app
from app import models
This is the beginning of the Traceback on Heroku:
2021-06-23T06:31:26.214788+00:00 app[web.1]: [2021-06-23 06:31:26 +0000] [10] [ERROR] Exception in worker process
2021-06-23T06:31:26.214792+00:00 app[web.1]: Traceback (most recent call last):
2021-06-23T06:31:26.214793+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-23T06:31:26.214794+00:00 app[web.1]: worker.init_process()
2021-06-23T06:31:26.214794+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-23T06:31:26.214795+00:00 app[web.1]: self.load_wsgi()
2021-06-23T06:31:26.214795+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-23T06:31:26.214795+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-23T06:31:26.214796+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-23T06:31:26.214796+00:00 app[web.1]: self.callable = self.load()
2021-06-23T06:31:26.214797+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-23T06:31:26.214797+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-23T06:31:26.214797+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-23T06:31:26.214798+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-23T06:31:26.214798+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-23T06:31:26.214798+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-23T06:31:26.214799+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-23T06:31:26.214800+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-23T06:31:26.214800+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-23T06:31:26.214800+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-23T06:31:26.214801+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2021-06-23T06:31:26.214801+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2021-06-23T06:31:26.214801+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2021-06-23T06:31:26.214802+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-06-23T06:31:26.214802+00:00 app[web.1]: File "/app/wsgi.py", line 1, in <module>
2021-06-23T06:31:26.214802+00:00 app[web.1]: from app import create_app
2021-06-23T06:31:26.214803+00:00 app[web.1]: File "/app/app/__init__.py", line 2, in <module>
2021-06-23T06:31:26.214803+00:00 app[web.1]: from config import Config
My folder structure pretty much looks like this:
app (folder) --> init.py
# root level
Procfile
wsgi.py
Pipfile
Pipfile.lock
config.py
.env
Upvotes: 0
Views: 177
Reputation: 581
The above details are all correct. I made the silly mistake of having a .gitignore file in the directory which was preventing .env from being pushed.
Upvotes: 1