3

I was making a Django web app using pipenv, the Application error window pops up whenever i try running 'heroku open', please help i am stuck in deploying this for over one month and have tried almost every possible solution that was available online but the error still persists. please help.

Running'heroku logs --tail' shows:

 $ heroku logs --tail
    2021-02-17T17:50:51.188410+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
    2021-02-17T17:50:51.297606+00:00 heroku[web.1]: Process exited with status 1
    2021-02-17T17:50:51.389796+00:00 heroku[web.1]: State changed from starting to crashed
    2021-02-17T17:50:53.000000+00:00 app[api]: Build succeeded
    2021-02-17T17:51:39.619675+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bloggero.herokuapp.com request_id=ecbd78a2-5542-4d08-87f7-e7d12404ae9b fwd="223.239.61.176" dyno= connect= service= status=503 bytes= protocol=https
    2021-02-17T17:51:41.855171+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bloggero.herokuapp.com request_id=42dd37d3-ad4b-43dc-956d-41d34bf03ffd fwd="223.239.61.176" dyno= connect= service= status=503 bytes= protocol=https
    2021-02-17T18:04:58.000000+00:00 app[api]: Build started by user ad******@gmail.com
    2021-02-17T18:05:29.716771+00:00 app[api]: Deploy 879be0de by user a******@gmail.com
    2021-02-17T18:05:29.716771+00:00 app[api]: Release v19 created by user a*******@gmail.com
    2021-02-17T18:05:30.074089+00:00 heroku[web.1]: State changed from crashed to starting
    2021-02-17T18:05:35.396728+00:00 heroku[web.1]: Starting process with command `gunicorn mysite.wsgi`
    2021-02-17T18:05:37.756029+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [4] [INFO] Starting gunicorn 20.0.4
    2021-02-17T18:05:37.756584+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [4] [INFO] Listening at: http://0.0.0.0:17786 (4)
    2021-02-17T18:05:37.756675+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [4] [INFO] Using worker: sync
    2021-02-17T18:05:37.761624+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [9] [INFO] Booting worker with pid: 9
    2021-02-17T18:05:37.770211+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [9] [ERROR] Exception in worker process
    2021-02-17T18:05:37.770213+00:00 app[web.1]: Traceback (most recent call last):
    2021-02-17T18:05:37.770232+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    2021-02-17T18:05:37.770233+00:00 app[web.1]: worker.init_process()
    2021-02-17T18:05:37.770234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    2021-02-17T18:05:37.770234+00:00 app[web.1]: self.load_wsgi()
    2021-02-17T18:05:37.770234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    2021-02-17T18:05:37.770235+00:00 app[web.1]: self.wsgi = self.app.wsgi()
    2021-02-17T18:05:37.770235+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    2021-02-17T18:05:37.770236+00:00 app[web.1]: self.callable = self.load()
    2021-02-17T18:05:37.770236+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    2021-02-17T18:05:37.770236+00:00 app[web.1]: return self.load_wsgiapp()
    2021-02-17T18:05:37.770237+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    2021-02-17T18:05:37.770237+00:00 app[web.1]: return util.import_app(self.app_uri)
    2021-02-17T18:05:37.770238+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    2021-02-17T18:05:37.770238+00:00 app[web.1]: mod = importlib.import_module(module)
    2021-02-17T18:05:37.770238+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
    2021-02-17T18:05:37.770239+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
    2021-02-17T18:05:37.770239+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    2021-02-17T18:05:37.770240+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    2021-02-17T18:05:37.770240+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
    2021-02-17T18:05:37.770240+00:00 app[web.1]: ModuleNotFoundError: No module named 'mysite.wsgi'
    2021-02-17T18:05:37.770465+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [9] [INFO] Worker exiting (pid: 9)
    2021-02-17T18:05:37.779801+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [10] [INFO] Booting worker with pid: 10
    2021-02-17T18:05:37.785931+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [10] [ERROR] Exception in worker process
    2021-02-17T18:05:37.785933+00:00 app[web.1]: Traceback (most recent call last):
    2021-02-17T18:05:37.785934+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    2021-02-17T18:05:37.785934+00:00 app[web.1]: worker.init_process()
    2021-02-17T18:05:37.785934+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    2021-02-17T18:05:37.785935+00:00 app[web.1]: self.load_wsgi()
    2021-02-17T18:05:37.785935+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    2021-02-17T18:05:37.785936+00:00 app[web.1]: self.wsgi = self.app.wsgi()
    2021-02-17T18:05:37.785937+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    2021-02-17T18:05:37.785937+00:00 app[web.1]: self.callable = self.load()
    2021-02-17T18:05:37.785937+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    2021-02-17T18:05:37.785938+00:00 app[web.1]: return self.load_wsgiapp()
    2021-02-17T18:05:37.785938+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    2021-02-17T18:05:37.785939+00:00 app[web.1]: return util.import_app(self.app_uri)
    2021-02-17T18:05:37.785939+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    2021-02-17T18:05:37.785939+00:00 app[web.1]: mod = importlib.import_module(module)
    2021-02-17T18:05:37.785940+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
    2021-02-17T18:05:37.785940+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
    2021-02-17T18:05:37.785941+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    2021-02-17T18:05:37.785941+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    2021-02-17T18:05:37.785941+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
    2021-02-17T18:05:37.785942+00:00 app[web.1]: ModuleNotFoundError: No module named 'mysite.wsgi'
    2021-02-17T18:05:37.786104+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [10] [INFO] Worker exiting (pid: 10)
    2021-02-17T18:05:37.906870+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [4] [INFO] Shutting down: Master
    2021-02-17T18:05:37.906946+00:00 app[web.1]: [2021-02-17 18:05:37 +0000] [4] [INFO] Reason: Worker failed to boot.
    2021-02-17T18:05:37.987061+00:00 heroku[web.1]: Process exited with status 3
    2021-02-17T18:05:38.059333+00:00 heroku[web.1]: State changed from starting to crashed
    2021-02-17T18:05:38.062623+00:00 heroku[web.1]: State changed from crashed to starting
    2021-02-17T18:05:41.000000+00:00 app[api]: Build succeeded
    2021-02-17T18:05:48.981104+00:00 heroku[web.1]: Starting process with command `gunicorn mysite.wsgi`
    2021-02-17T18:05:52.073363+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [4] [INFO] Starting gunicorn 20.0.4
    2021-02-17T18:05:52.074407+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [4] [INFO] Listening at: http://0.0.0.0:45799 (4)
    2021-02-17T18:05:52.074661+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [4] [INFO] Using worker: sync
    2021-02-17T18:05:52.082772+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [9] [INFO] Booting worker with pid: 9
    2021-02-17T18:05:52.096292+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [9] [ERROR] Exception in worker process
    2021-02-17T18:05:52.096293+00:00 app[web.1]: Traceback (most recent call last):
    2021-02-17T18:05:52.096302+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    2021-02-17T18:05:52.096303+00:00 app[web.1]: worker.init_process()
    2021-02-17T18:05:52.096303+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    2021-02-17T18:05:52.096303+00:00 app[web.1]: self.load_wsgi()
    2021-02-17T18:05:52.096304+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    2021-02-17T18:05:52.096304+00:00 app[web.1]: self.wsgi = self.app.wsgi()
    2021-02-17T18:05:52.096304+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    2021-02-17T18:05:52.096305+00:00 app[web.1]: self.callable = self.load()
    2021-02-17T18:05:52.096305+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    2021-02-17T18:05:52.096306+00:00 app[web.1]: return self.load_wsgiapp()
    2021-02-17T18:05:52.096306+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    2021-02-17T18:05:52.096306+00:00 app[web.1]: return util.import_app(self.app_uri)
    2021-02-17T18:05:52.096307+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    2021-02-17T18:05:52.096307+00:00 app[web.1]: mod = importlib.import_module(module)
    2021-02-17T18:05:52.096307+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
    2021-02-17T18:05:52.096308+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
    2021-02-17T18:05:52.096308+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    2021-02-17T18:05:52.096309+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    2021-02-17T18:05:52.096309+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
    2021-02-17T18:05:52.096310+00:00 app[web.1]: ModuleNotFoundError: No module named 'mysite.wsgi'
    2021-02-17T18:05:52.096657+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [9] [INFO] Worker exiting (pid: 9)
    2021-02-17T18:05:52.131656+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [4] [INFO] Shutting down: Master
    2021-02-17T18:05:52.131783+00:00 app[web.1]: [2021-02-17 18:05:52 +0000] [4] [INFO] Reason: Worker failed to boot.
    2021-02-17T18:05:52.238783+00:00 heroku[web.1]: Process exited with status 3
    2021-02-17T18:05:52.335630+00:00 heroku[web.1]: State changed from starting to crashed

I checked the Procfile and it looks :

    web: gunicorn mysite.wsgi

And here is the wsgi.py module:

    from helloworld.wsgi import HelloWorldApplication
    import os
    
    from django.core.wsgi import get_wsgi_application
    
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
    
    application = get_wsgi_application()
    
    
    application = HelloWorldApplication(application)

The project structure is as follows-

enter image description here

And i have already installed gunicorn and other requirements which can be seen here in the pipfile:-

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
asgiref = "==3.2.10"
django-crispy-forms = "==1.10.0"
pytz = "==2020.4"
sqlparse = "==0.4.1"
Django = "==3.1"
Pillow = "==8.0.1"
gunicorn = "*"

[requires]
python_version = "3.7"

2 Answers2

1

From a quick google search I found another thread with a similar question. The answers seem to indicate that you need to add your project directory in your python path.

First, import the sys module.

import sys

Now, right before the os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') line, add:

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

if path not in sys.path:
    sys.path.append(path)

This code snippet grabs the absolute path to your project directory and appends it to your python path if it is not already there. Also, I second Field Boy's response that you should consider a linux server.

0

Please don't waste your time with heroku, you will always run into problems, even after your app started fine, if your app is fairly large. Use a virtual machine (check digital ocean or linode they have free $100 credit) and your app will run just like on your laptop. Look for Corey Schafer Django deployment on linux server on youtube on how to set up Apache2 virtual server on the linux server.

Yankz Kuyateh
  • 612
  • 1
  • 5
  • 18