Reputation: 105
Update: I made a breakthrough in understanding what my problem is, which I'll state below.
I am attempting to deploy a django project to Heroku and I'm stumped with this error right at the bottom:
2022-03-04T03:32:53.360457+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath backend.core backend.core.wsgi --log-file -`
2022-03-04T03:32:55.579764+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-04T03:32:54.908542+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-03-04T03:32:54.908855+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [4] [INFO] Listening at: http://0.0.0.0:39265 (4)
2022-03-04T03:32:54.908899+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [4] [INFO] Using worker: sync
2022-03-04T03:32:54.912389+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [9] [INFO] Booting worker with pid: 9
2022-03-04T03:32:54.974193+00:00 app[web.1]: [2022-03-04 03:32:54 +0000] [10] [INFO] Booting worker with pid: 10
2022-03-04T03:32:55.113641+00:00 app[web.1]: [2022-03-04 03:32:55 +0000] [9] [ERROR] Exception in worker process
2022-03-04T03:32:55.113643+00:00 app[web.1]: Traceback (most recent call last):
2022-03-04T03:32:55.113660+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-03-04T03:32:55.113661+00:00 app[web.1]: worker.init_process()
2022-03-04T03:32:55.113661+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-03-04T03:32:55.113661+00:00 app[web.1]: self.load_wsgi()
2022-03-04T03:32:55.113662+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-03-04T03:32:55.113662+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-03-04T03:32:55.113662+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-03-04T03:32:55.113663+00:00 app[web.1]: self.callable = self.load()
2022-03-04T03:32:55.113663+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-03-04T03:32:55.113663+00:00 app[web.1]: return self.load_wsgiapp()
2022-03-04T03:32:55.113663+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-03-04T03:32:55.113664+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-03-04T03:32:55.113664+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
2022-03-04T03:32:55.113664+00:00 app[web.1]: mod = importlib.import_module(module)
2022-03-04T03:32:55.113665+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-03-04T03:32:55.113665+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-03-04T03:32:55.113665+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-03-04T03:32:55.113666+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-03-04T03:32:55.113667+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-03-04T03:32:55.113667+00:00 app[web.1]: File "/app/backend/core/wsgi.py", line 16, in <module>
2022-03-04T03:32:55.113667+00:00 app[web.1]: application = get_wsgi_application()
2022-03-04T03:32:55.113667+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2022-03-04T03:32:55.113668+00:00 app[web.1]: django.setup(set_prefix=False)
2022-03-04T03:32:55.113668+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/__init__.py", line 19, in setup
2022-03-04T03:32:55.113668+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2022-03-04T03:32:55.113668+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 87, in __getattr__
2022-03-04T03:32:55.113668+00:00 app[web.1]: self._setup(name)
2022-03-04T03:32:55.113669+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 74, in _setup
2022-03-04T03:32:55.113669+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2022-03-04T03:32:55.113669+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/django/conf/__init__.py", line 183, in __init__
2022-03-04T03:32:55.113669+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2022-03-04T03:32:55.113670+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-03-04T03:32:55.113670+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-03-04T03:32:55.113670+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-03-04T03:32:55.113670+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-03-04T03:32:55.113671+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
2022-03-04T03:32:55.113671+00:00 app[web.1]: ModuleNotFoundError: No module named 'core'
2022-03-04T03:32:55.113893+00:00 app[web.1]: [2022-03-04 03:32:55 +0000] [9] [INFO] Worker exiting (pid: 9)
2022-03-04T03:32:55.148185+00:00 app[web.1]: [2022-03-04 03:32:55 +0000] [10] [ERROR] Exception in worker process
In attempt to provide some information, inside my procfile
web: gunicorn --pythonpath backend.core backend.core.wsgi --log-file -
release: python backend.manage.py makemigrations - - no-input
Inside requirements.txt
asgiref==3.5.0
attrs==21.4.0
beautifulsoup4==4.10.0
bs4==0.0.1
certifi==2021.10.8
charset-normalizer==2.0.12
Django==4.0.3
django-core==1.4.1
django-cors-headers==3.11.0
django-filter==21.1
djangorestframework==3.13.1
gunicorn==20.1.0
idna==3.3
jsonlines==3.0.0
lxml==4.8.0
pytz==2021.3
requests==2.27.1
soupsieve==2.3.1
sqlparse==0.4.2
urllib3==1.26.8
virtualenv-tools3==2.0.5
whitenoise==6.0.0
And I have my project set up as
FE_APP/
runtime.txt
requirements.txt
Procfile
backend/
scraper.py
Under FE_APP/backend/
api/
core/
static/
db.sqlite3
manage.py
and in FE_APP/backend/core/
__init__.py
errorlog
settings.py
urls.py
wsgi.py
In FE_APP/backend/api/
, I have my views.py
that does import from core.settings a couple variables.
from core.settings import REALMS, GAME_TITLES
But I doubt that's a concern for why this deployment is bugging out on me. I can deploy on my local machine just fine but heroku keeps giving me this error. I feel like I'm so close to deploying, what is going on?
March 7 update EDIT: I initially had the folder that contained settings.py and wsgi.py named 'core' and I recently changed it to 'feh' following this tutorial here. Now when I run the heroku local
command on terminal, I get the error
ModuleNotFoundError: No module named 'feh'
Among other junk, leading me to believe there's no conflict between any django core module name conflicts with the folder. I don't know how to beat this, but I'm making progress at least.
Upvotes: 0
Views: 659
Reputation: 105
While I still haven't fully solved deployment as I still have another obstacle to figure out (which I will probably make another post for), I think I solved this one by adding to my wsgi.py file the whitenoise module and implementation below:
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise import WhiteNoise
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'feh.settings')
application = get_wsgi_application()
application = WhiteNoise(application)
EDIT: I also had another error that caused a heroku deployment failure where it could not find my manage.py file. this was caused by my Procfile not being set up properly,
Procfile
needed to be set up as so.
web: gunicorn --pythonpath backend feh.wsgi --log-file -
release: python backend/manage.py makemigrations --no-input
backend is the directory of the django project but it's not the root directory of project to be deployed, hence --pythonpath is needed to specify the django project directory. And I suppose the space in my --no-input flag also caused errors. Thank you Chris. After these and perhaps working some magic with gunicorn and whitenoise and the django-heroku modules (can't remember if this was before or after, sorry), I got it to work.
Upvotes: 1