I've been having some trouble getting my Django app with the django rest framework to deploy without errors to heroku. The strange thing is, there would be no issues in pushing and deploying to Heroku but would crash after deployment. Here is my file structure:
Include/
man/
Procfile/
requirements.txt
runtime.txt
Scripts/
tcl/
webadvisorapi
│ manage.py
├───src
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ serializers.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───management
│ │ │ __init__.py
│ │ │
│ │ └───commands
│ │ runrequest.py
│ │ __init__.py
│ │
│ ├───scripts
│ request.py
│ __init__.py
│
├───static
│ .keep
│
├───staticfiles
└───webadvisorapi
│ settings.py
│ urls.py
│ wsgi.py
│ __init__.py
│
├───static
│ .keep
I have already ran this on my own machine and it worked just fine. Interestingly, my app could not be pushed and deployed to Heroku when I use any other path other than src.apps.SrcConfig in INSTALLED_APPS as it gives me the same ModuleNotFoundError. Besides that, I did get a successful deployment but the app crashed. I even cloned my project from heroku and ran my project locally and there was no issue. Here is the log from heroku logs --tail:
2019-07-13T06:43:31.172615+00:00 heroku[web.1]: Starting process with command `gunicorn webadvisorapi.webadvisorapi.wsgi --log-file -`
2019-07-13T06:43:33.243340+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-07-13T06:43:33.243849+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [4] [INFO] Listening at: http://0.0.0.0:34512 (4)
2019-07-13T06:43:33.243940+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [4] [INFO] Using worker: sync
2019-07-13T06:43:33.249546+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [10] [INFO] Booting worker with pid: 10
2019-07-13T06:43:33.350998+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [11] [INFO] Booting worker with pid: 11
2019-07-13T06:43:33.524337+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [10] [ERROR] Exception in worker
process
2019-07-13T06:43:33.524355+00:00 app[web.1]: Traceback (most recent call last):
2019-07-13T06:43:33.524394+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-07-13T06:43:33.524397+00:00 app[web.1]: worker.init_process()
2019-07-13T06:43:33.524399+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-07-13T06:43:33.524401+00:00 app[web.1]: self.load_wsgi()
2019-07-13T06:43:33.524403+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-07-13T06:43:33.524405+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-07-13T06:43:33.524413+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-07-13T06:43:33.524415+00:00 app[web.1]: self.callable = self.load()
2019-07-13T06:43:33.524417+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-07-13T06:43:33.524419+00:00 app[web.1]: return self.load_wsgiapp()
2019-07-13T06:43:33.524421+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-07-13T06:43:33.524423+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-07-13T06:43:33.524425+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2019-07-13T06:43:33.524426+00:00 app[web.1]: __import__(module)
2019-07-13T06:43:33.524428+00:00 app[web.1]: File "/app/webadvisorapi/webadvisorapi/wsgi.py", line 17, in
<module>
2019-07-13T06:43:33.524430+00:00 app[web.1]: application = get_wsgi_application()
2019-07-13T06:43:33.524432+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-07-13T06:43:33.524434+00:00 app[web.1]: django.setup(set_prefix=False)
2019-07-13T06:43:33.524436+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2019-07-13T06:43:33.524438+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2019-07-13T06:43:33.524440+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
2019-07-13T06:43:33.524442+00:00 app[web.1]: app_config = AppConfig.create(entry)
2019-07-13T06:43:33.524444+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
2019-07-13T06:43:33.524445+00:00 app[web.1]: mod = import_module(mod_path)
2019-07-13T06:43:33.524447+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2019-07-13T06:43:33.524454+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-07-13T06:43:33.524457+00:00 app[web.1]: ModuleNotFoundError: No module named 'src'
2019-07-13T06:43:33.524572+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [10] [INFO] Worker exiting (pid:
10)
2019-07-13T06:43:33.676529+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [11] [ERROR] Exception in worker
process
2019-07-13T06:43:33.676532+00:00 app[web.1]: Traceback (most recent call last):
2019-07-13T06:43:33.676535+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-07-13T06:43:33.676537+00:00 app[web.1]: worker.init_process()
2019-07-13T06:43:33.676538+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-07-13T06:43:33.676540+00:00 app[web.1]: self.load_wsgi()
2019-07-13T06:43:33.676541+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-07-13T06:43:33.676543+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-07-13T06:43:33.676545+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-07-13T06:43:33.676547+00:00 app[web.1]: self.callable = self.load()
2019-07-13T06:43:33.676549+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-07-13T06:43:33.676550+00:00 app[web.1]: return self.load_wsgiapp()
2019-07-13T06:43:33.676552+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-07-13T06:43:33.676553+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-07-13T06:43:33.676555+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2019-07-13T06:43:33.676556+00:00 app[web.1]: __import__(module)
2019-07-13T06:43:33.676558+00:00 app[web.1]: File "/app/webadvisorapi/webadvisorapi/wsgi.py", line 17, in
<module>
2019-07-13T06:43:33.676559+00:00 app[web.1]: application = get_wsgi_application()
2019-07-13T06:43:33.676561+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-07-13T06:43:33.676562+00:00 app[web.1]: django.setup(set_prefix=False)
2019-07-13T06:43:33.676564+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2019-07-13T06:43:33.676565+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2019-07-13T06:43:33.676567+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
2019-07-13T06:43:33.676568+00:00 app[web.1]: app_config = AppConfig.create(entry)
2019-07-13T06:43:33.676569+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
2019-07-13T06:43:33.676571+00:00 app[web.1]: mod = import_module(mod_path)
2019-07-13T06:43:33.676572+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2019-07-13T06:43:33.676574+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-07-13T06:43:33.676576+00:00 app[web.1]: ModuleNotFoundError: No module named 'src'
2019-07-13T06:43:33.676797+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [11] [INFO] Worker exiting (pid:
11)
2019-07-13T06:43:33.743217+00:00 app[web.1]: Traceback (most recent call last):
2019-07-13T06:43:33.743229+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 210, in run
2019-07-13T06:43:33.743551+00:00 app[web.1]: self.sleep()
2019-07-13T06:43:33.743557+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 360, in sleep
2019-07-13T06:43:33.743786+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2019-07-13T06:43:33.743792+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2019-07-13T06:43:33.743969+00:00 app[web.1]: self.reap_workers()
2019-07-13T06:43:33.744000+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2019-07-13T06:43:33.744238+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2019-07-13T06:43:33.744322+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2019-07-13T06:43:33.744327+00:00 app[web.1]:
2019-07-13T06:43:33.744330+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2019-07-13T06:43:33.744332+00:00 app[web.1]:
2019-07-13T06:43:33.744336+00:00 app[web.1]: Traceback (most recent call last):
2019-07-13T06:43:33.744346+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2019-07-13T06:43:33.744482+00:00 app[web.1]: sys.exit(run())
2019-07-13T06:43:33.744486+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
2019-07-13T06:43:33.744632+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2019-07-13T06:43:33.744639+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 223, in run
2019-07-13T06:43:33.744843+00:00 app[web.1]: super(Application, self).run()
2019-07-13T06:43:33.744850+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 72, in run
2019-07-13T06:43:33.744985+00:00 app[web.1]: Arbiter(self).run()
2019-07-13T06:43:33.744991+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 232, in run
2019-07-13T06:43:33.745162+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2019-07-13T06:43:33.745168+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 345, in halt
2019-07-13T06:43:33.745377+00:00 app[web.1]: self.stop()
2019-07-13T06:43:33.745411+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 393, in stop
2019-07-13T06:43:33.745611+00:00 app[web.1]: time.sleep(0.1)
2019-07-13T06:43:33.745617+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2019-07-13T06:43:33.745787+00:00 app[web.1]: self.reap_workers()
2019-07-13T06:43:33.745793+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2019-07-13T06:43:33.746031+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2019-07-13T06:43:33.746074+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
settings.py (I omitted things that I thought were not relevant)
import django_heroku
import dj_database_url
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'src.apps.SrcConfig',
'corsheaders',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
ROOT_URLCONF = 'webadvisorapi.urls'
WSGI_APPLICATION = 'webadvisorapi.wsgi.application'
STATIC_URL = '/static/'
django_heroku.settings(locals())
Procfile
web: gunicorn webadvisorapi.webadvisorapi.wsgi --log-file -
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webadvisorapi.webadvisorapi.settings')
application = get_wsgi_application()
apps.py
from django.apps import AppConfig
class SrcConfig(AppConfig):
name = 'src'
webadvisorapi/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('src.urls')),
]
I'm really not sure what the problem is here, given that this path worked fine in my localhost. I would appreciate any kind of help.
Related
Build is successdul and it is producing application error, i have set up host name and debug=False as suggested but it is still causing error in opening the browser window, i am new to heroku so please suggest what needs to be done to make it work
my settings.py
"""
Django settings for djangoTut project.
Generated by 'django-admin startproject' using Django 3.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
print(BASE_DIR)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = mysecretkey
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['djangoblog-project.herokuapp.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'djangoTut.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'djangoTut.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'DATABASE' : 'DjangoProject',
'NAME': 'DjangoProject',
'USER' : 'myprojectuser',
'PASSWORD' : 'Akbar#123456',
'HOST': 'localhost',
'PORT': '',
# 'default-character-se' : 'utf8',
# 'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
STATICFILES_DIRS = [
]
CRISPY_TEMPLATE_PACK = 'bootstrap4'
# STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
LOGIN_REDIRECT_URL = 'blogHome'
LOGIN_URL = 'login'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
requirements.txt for the current django project
requirements.txt
boto3==1.9.96
botocore==1.12.96
certifi==2018.10.15
chardet==3.0.4
dj-database-url==0.5.0
Django==2.1
django-crispy-forms==1.7.2
django-heroku==0.3.1
django-storages==1.7.1
docutils==0.14
gunicorn==19.9.0
idna==2.7
jmespath==0.9.3
Pillow==5.2.0
python-dateutil==2.8.0
pytz==2018.5
requests==2.19.1
s3transfer==0.2.0
six==1.12.0
urllib3==1.23
whitenoise==4.1.2
heroku logs
› Warning: heroku update available from 7.52.0 to 7.54.0.
2021-06-12T09:49:28.101517+00:00 app[web.1]: Arbiter(self).run()
2021-06-12T09:49:28.101521+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 232, in run
2021-06-12T09:49:28.101745+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2021-06-12T09:49:28.101747+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 345, in halt
2021-06-12T09:49:28.101999+00:00 app[web.1]: self.stop()
2021-06-12T09:49:28.102004+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 393, in stop
2021-06-12T09:49:28.102241+00:00 app[web.1]: time.sleep(0.1)
2021-06-12T09:49:28.102246+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2021-06-12T09:49:28.102398+00:00 app[web.1]: self.reap_workers()
2021-06-12T09:49:28.102404+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-06-12T09:49:28.102716+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2021-06-12T09:49:28.102754+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-06-12T09:49:28.205668+00:00 heroku[web.1]: Process exited with status 1
2021-06-12T09:49:28.284579+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-12T09:49:34.912538+00:00 app[api]: Release v9 created by user dhruv.singhal2612#gmail.com
2021-06-12T09:49:34.912538+00:00 app[api]: Set DEBUG_VALUE config vars by user dhruv.singhal2612#gmail.com
2021-06-12T09:49:35.143657+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-12T09:49:41.619208+00:00 heroku[web.1]: Starting process with command `gunicorn django_project.wsgi`
2021-06-12T09:49:45.299640+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [4] [INFO] Starting gunicorn 19.9.0
2021-06-12T09:49:45.300103+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [4] [INFO] Listening at: http://0.0.0.0:16332 (4)
2021-06-12T09:49:45.300346+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [4] [INFO] Using worker: sync
2021-06-12T09:49:45.302082+00:00 app[web.1]: /app/.heroku/python/lib/python3.9/os.py:1023: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
2021-06-12T09:49:45.302083+00:00 app[web.1]: return io.open(fd, *args, **kwargs)
2021-06-12T09:49:45.306106+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [7] [INFO] Booting worker with pid: 7
2021-06-12T09:49:45.312314+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [7] [ERROR] Exception in worker process
2021-06-12T09:49:45.312315+00:00 app[web.1]: Traceback (most recent call last):
2021-06-12T09:49:45.312326+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-06-12T09:49:45.312326+00:00 app[web.1]: worker.init_process()
2021-06-12T09:49:45.312327+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 129, in init_process
2021-06-12T09:49:45.312328+00:00 app[web.1]: self.load_wsgi()
2021-06-12T09:49:45.312328+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2021-06-12T09:49:45.312328+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-12T09:49:45.312329+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-12T09:49:45.312329+00:00 app[web.1]: self.callable = self.load()
2021-06-12T09:49:45.312329+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2021-06-12T09:49:45.312330+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-12T09:49:45.312330+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2021-06-12T09:49:45.312331+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-12T09:49:45.312331+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 350, in import_app
2021-06-12T09:49:45.312331+00:00 app[web.1]: __import__(module)
2021-06-12T09:49:45.312332+00:00 app[web.1]: ModuleNotFoundError: No module named 'django_project'
2021-06-12T09:49:45.312475+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-06-12T09:49:45.342275+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [8] [INFO] Booting worker with pid: 8
2021-06-12T09:49:45.354724+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [8] [ERROR] Exception in worker process
2021-06-12T09:49:45.354725+00:00 app[web.1]: Traceback (most recent call last):
2021-06-12T09:49:45.354726+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-06-12T09:49:45.354726+00:00 app[web.1]: worker.init_process()
2021-06-12T09:49:45.354727+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 129, in init_process
2021-06-12T09:49:45.354727+00:00 app[web.1]: self.load_wsgi()
2021-06-12T09:49:45.354728+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2021-06-12T09:49:45.354728+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-12T09:49:45.354728+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-12T09:49:45.354729+00:00 app[web.1]: self.callable = self.load()
2021-06-12T09:49:45.354729+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2021-06-12T09:49:45.354730+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-12T09:49:45.354730+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2021-06-12T09:49:45.354730+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-12T09:49:45.354731+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/util.py", line 350, in import_app
2021-06-12T09:49:45.354731+00:00 app[web.1]: __import__(module)
2021-06-12T09:49:45.354732+00:00 app[web.1]: ModuleNotFoundError: No module named 'django_project'
2021-06-12T09:49:45.354973+00:00 app[web.1]: [2021-06-12 09:49:45 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-06-12T09:49:45.396511+00:00 app[web.1]: Traceback (most recent call last):
2021-06-12T09:49:45.396519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 203, in run
2021-06-12T09:49:45.396872+00:00 app[web.1]: self.manage_workers()
2021-06-12T09:49:45.396873+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 545, in manage_workers
2021-06-12T09:49:45.397354+00:00 app[web.1]: self.spawn_workers()
2021-06-12T09:49:45.397381+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 617, in spawn_workers
2021-06-12T09:49:45.397935+00:00 app[web.1]: time.sleep(0.1 * random.random())
2021-06-12T09:49:45.397962+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2021-06-12T09:49:45.398390+00:00 app[web.1]: self.reap_workers()
2021-06-12T09:49:45.398463+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-06-12T09:49:45.398958+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2021-06-12T09:49:45.399217+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-06-12T09:49:45.399240+00:00 app[web.1]:
2021-06-12T09:49:45.399240+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-06-12T09:49:45.399241+00:00 app[web.1]:
2021-06-12T09:49:45.399265+00:00 app[web.1]: Traceback (most recent call last):
2021-06-12T09:49:45.399340+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2021-06-12T09:49:45.399650+00:00 app[web.1]: sys.exit(run())
2021-06-12T09:49:45.399677+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
2021-06-12T09:49:45.400017+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2021-06-12T09:49:45.400048+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 223, in run
2021-06-12T09:49:45.400760+00:00 app[web.1]: super(Application, self).run()
2021-06-12T09:49:45.400788+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/app/base.py", line 72, in run
2021-06-12T09:49:45.401131+00:00 app[web.1]: Arbiter(self).run()
2021-06-12T09:49:45.401164+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 232, in run
2021-06-12T09:49:45.401541+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2021-06-12T09:49:45.401569+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 345, in halt
2021-06-12T09:49:45.402002+00:00 app[web.1]: self.stop()
2021-06-12T09:49:45.402029+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 393, in stop
2021-06-12T09:49:45.402490+00:00 app[web.1]: time.sleep(0.1)
2021-06-12T09:49:45.402519+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2021-06-12T09:49:45.403126+00:00 app[web.1]: self.reap_workers()
2021-06-12T09:49:45.403154+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-06-12T09:49:45.403652+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2021-06-12T09:49:45.403847+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-06-12T09:49:45.504630+00:00 heroku[web.1]: Process exited with status 1
2021-06-12T09:49:45.573000+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-12T09:50:28.064356+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=djangoblog-project.herokuapp.com request_id=55fab425-ef64-485a-892c-cbf2120401ce fwd="223.184.234.62" dyno= connect= service= status=503 bytes= protocol=https
2021-06-12T09:50:28.695891+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=djangoblog-project.herokuapp.com request_id=2c5d885e-39a1-4683-aa17-28efabadd898 fwd="223.184.234.62" dyno= connect= service= status=503 bytes= protocol=https
If you are using django-heroku package than you have to add this in your settings.py
Add the following import statement to the top of settings.py:
import django_heroku
and Then add the following to the bottom of settings.py:
# Activate Django-Heroku.
django_heroku.settings(locals())
check official doc. https://devcenter.heroku.com/articles/django-app-configuration#settings-py-changes
Did you create the Procfile file in the project folder?
If you are using Windows PS, you can type in terminal:
echo web: gunicorn <<YOUR_PROJECT>>.wsgi --log-file - > Procfile
Another possible solution is to use Postgres instead of MySQL:
In settings.py:
DATABASES = {
'default': dj_database_url.config()
}
In requirements.txt:
psycopg2-binary==2.8.6
I was going to host it using Heroku. But it does not work because of the problem with the profile.
This my Procfile
web: gunicorn onlineMenu.wsgi --log-file -
my wsgi.py code
"""
WSGI config for onlineMenu project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'onlineMenu.settings')
application = get_wsgi_application()
this is my Heroku log (not all)
2020-10-23T16:04:08.861587+00:00 app[web.1]: Traceback (most recent
call last): 2020-10-23T16:04:08.861588+00:00 app[web.1]: File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py",
line 583, in spawn_worker 2020-10-23T16:04:08.861588+00:00 app[web.1]:
worker.init_process() 2020-10-23T16:04:08.861589+00:00 app[web.1]:
File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py",
line 119, in init_process 2020-10-23T16:04:08.861589+00:00 app[web.1]:
self.load_wsgi() 2020-10-23T16:04:08.861589+00:00 app[web.1]: File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py",
line 144, in load_wsgi 2020-10-23T16:04:08.861590+00:00 app[web.1]:
self.wsgi = self.app.wsgi() 2020-10-23T16:04:08.861590+00:00
app[web.1]: File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py",
line 67, in wsgi 2020-10-23T16:04:08.861590+00:00 app[web.1]:
self.callable = self.load() 2020-10-23T16:04:08.861591+00:00
app[web.1]: File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py",
line 49, in load 2020-10-23T16:04:08.861591+00:00 app[web.1]: return
self.load_wsgiapp() 2020-10-23T16:04:08.861591+00:00 app[web.1]: File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py",
line 39, in load_wsgiapp 2020-10-23T16:04:08.861592+00:00 app[web.1]:
return util.import_app(self.app_uri) 2020-10-23T16:04:08.861592+00:00
app[web.1]: File
"/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py",
line 358, in import_app 2020-10-23T16:04:08.861592+00:00 app[web.1]:
mod = importlib.import_module(module) 2020-10-23T16:04:08.861593+00:00
app[web.1]: File
"/app/.heroku/python/lib/python3.8/importlib/init.py", line 127,
in import_module 2020-10-23T16:04:08.861593+00:00 app[web.1]: return
_bootstrap._gcd_import(name[level:], package, level) 2020-10-23T16:04:08.861593+00:00 app[web.1]: File "", line 1014, in _gcd_import
2020-10-23T16:04:08.861594+00:00 app[web.1]: File "", line 991, in _find_and_load
2020-10-23T16:04:08.861594+00:00 app[web.1]: File "", line 973, in _find_and_load_unlocked
2020-10-23T16:04:08.861594+00:00 app[web.1]: ModuleNotFoundError: No
module named 'onlineMenu/wsgi' 2020-10-23T16:04:08.861841+00:00
app[web.1]: [2020-10-23 16:04:08 +0000] [10] [INFO] Worker exiting
(pid: 10) 2020-10-23T16:04:09.011977+00:00 app[web.1]: [2020-10-23
16:04:09 +0000] [4] [INFO] Shutting down: Master
2020-10-23T16:04:09.012166+00:00 app[web.1]: [2020-10-23 16:04:09
+0000] [4] [INFO] Reason: Worker failed to boot.
Getting a stack of errors concluding to
"ImportError: No module named webpack_loader".
I have a Django app created that I'm trying to Docker using Gunicorn.
My Dockerfile and start.sh are in a root directory alongside another directory called approot. In approot is everything you'd expect to see from running django-admin startproject. My wsgi.py file is in a directory called app inside of approot.
Here is my...
requirements.txt:
Django>=1.8
gunicorn==19.6.0
Dockerfile:
#Dockerfile
# FROM directive instructing base image to build upon
FROM python:2-onbuild
# COPY startup script into known file location in container
COPY start.sh /start.sh
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
# CMD specifies the command to execute to start the server running
CMD ["/start.sh"]
start.sh:
#!/bin/bash
echo Starting Gunicorn.
cd approot
exec gunicorn app.wsgi:application \
--bind 0.0.0.0:8000 \
--workers 3
My settings.py includes:
INSTALLED_APPS = [
...,
'webpack_loader'
]
WSGI_APPLICATION = 'app.wsgi.application'
WEBPACK_LOADER = {
'DEFAULT': {
'CACHE': not DEBUG,
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE': join(PROJECT_ROOT, 'webpack-stats.json'),
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
}
}
error stack is
$ docker run -it -p 8000:8000 app
Starting Gunicorn.
[2017-10-31 02:23:31 +0000] [1] [INFO] Starting gunicorn 19.6.0
[2017-10-31 02:23:31 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2017-10-31 02:23:31 +0000] [1] [INFO] Using worker: sync
[2017-10-31 02:23:31 +0000] [8] [INFO] Booting worker with pid: 8
[2017-10-31 02:23:31 +0000] [9] [INFO] Booting worker with pid: 9
[2017-10-31 02:23:31 +0000] [12] [INFO] Booting worker with pid: 12
[2017-10-31 02:23:31 +0000] [8] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/usr/src/app/approot/app/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named webpack_loader
[2017-10-31 02:23:31 +0000] [8] [INFO] Worker exiting (pid: 8)
[2017-10-31 02:23:31 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/usr/src/app/approot/app/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named webpack_loader
[2017-10-31 02:23:31 +0000] [9] [INFO] Worker exiting (pid: 9)
Traceback (most recent call last):
File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 192, in run
super(Application, self).run()
File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 218, in run
self.halt(reason=inst.reason, exit_status=inst.exit_status)
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 331, in halt
self.stop()
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 381, in stop
time.sleep(0.1)
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 231, in handle_chld
self.reap_workers()
File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 506, in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
I think you're missing the django-webpack-loader in the requirements.txt
I have Been using this guide Getting Started with Django on Heroku
requirements.txt
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.7.7
django-toolbelt==0.0.1
djrill==1.3.0
gunicorn==19.3.0
Pillow==2.7.0
psycopg2==2.6
requests==2.6.0
static3==0.5.1
Procfile
web: gunicorn MY_DJANGO_APP.wsgi --log-file -
wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MY_DJANGO_APP.settings")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
Heroku log
State changed from crashed to starting
heroku[web.1]: Starting process with command `gunicorn MY_Django_App.wsgi --log-file -`
app[web.1]: [2015-03-29 07:17:55 +0000] [3] [INFO] Starting gunicorn 19.3.0
app[web.1]: [2015-03-29 07:17:56 +0000] [8] [INFO] Booting worker with pid: 8
app[web.1]: [2015-03-29 07:17:55 +0000] [3] [INFO] Listening at: http://0.0.0.0:17329 (3)
app[web.1]: [2015-03-29 07:17:55 +0000] [3] [INFO] Using worker: sync
app[web.1]: [2015-03-29 07:17:55 +0000] [7] [INFO] Booting worker with pid: 7
heroku[web.1]: State changed from starting to up
app[web.1]: [2015-03-29 07:17:56 +0000] [8] [ERROR] Exception in worker process:
app[web.1]: self.callable = self.load()
app[web.1]: return util.import_app(self.app_uri)
app[web.1]: File "/app/MY_Django_App/wsgi.py", line 17, in <module>
app[web.1]: Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
app[web.1]: Traceback (most recent call last):
app[web.1]: worker.init_process()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/dj_static.py", line 48, in __init__
app[web.1]: AttributeError: 'module' object has no attribute 'Cling'
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
app[web.1]: return self.load_wsgiapp()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/dj_static.py", line 48, in __init__
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: return self.load_wsgiapp()
app[web.1]: __import__(module)
app[web.1]: application = Cling(get_wsgi_application())
app[web.1]: AttributeError: 'module' object has no attribute 'Cling'
app[web.1]: application = Cling(get_wsgi_application())
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
app[web.1]: return util.import_app(self.app_uri)
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: __import__(module)
app[web.1]: self.cling = static.Cling(base_dir)
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
app[web.1]: [2015-03-29 07:17:56 +0000] [8] [INFO] Worker exiting (pid: 8)
app[web.1]: worker.init_process()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
app[web.1]: self.callable = self.load()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
app[web.1]: File "/app/MY_Django_App/wsgi.py", line 17, in <module>
app[web.1]: self.cling = static.Cling(base_dir)
app[web.1]: [2015-03-29 07:17:56 +0000] [7] [ERROR] Exception in worker process:
app[web.1]: worker.init_process()
app[web.1]: return self.load_wsgiapp()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/dj_static.py", line 48, in __init__
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
app[web.1]: File "/app/MY_Django_App/wsgi.py", line 17, in <module>
app[web.1]: Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
app[web.1]: __import__(module)
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
app[web.1]: __import__(module)
app[web.1]: self.cling = static.Cling(base_dir)
app[web.1]: return self.load_wsgiapp()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
app[web.1]: worker.init_process()
app[web.1]: self.callable = self.load()
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
app[web.1]: AttributeError: 'module' object has no attribute 'Cling'
app[web.1]: [2015-03-29 07:17:56 +0000] [3] [INFO] Shutting down: Master
app[web.1]: [2015-03-29 07:17:56 +0000] [3] [INFO] Reason: Worker failed to boot.
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
app[web.1]: self.cling = static.Cling(base_dir)
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
app[web.1]: File "/app/MY_Django_App/wsgi.py", line 17, in <module>
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/workers/base.py", line 118, in init_process
app[web.1]: self.callable = self.load()
app[web.1]: AttributeError: 'module' object has no attribute 'Cling'
app[web.1]: return util.import_app(self.app_uri)
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/dj_static.py", line 48, in __init__
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: return util.import_app(self.app_uri)
app[web.1]: Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
app[web.1]: application = Cling(get_wsgi_application())
app[web.1]: application = Cling(get_wsgi_application())
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: [2015-03-29 07:17:56 +0000] [7] [INFO] Worker exiting (pid: 7)
heroku[web.1]: State changed from up to crashed
heroku[web.1]: Process exited with status 3
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/feed" host=MY_Django_App.herokuapp.com request_id=e6de6503-58ea-4a05-b8fc-20321ace144a fwd="91.133.185.43" dyno=web.1 connect=5000ms service= status=503 bytes=
The more eye catching error
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: return self.load_wsgiapp()
app[web.1]: __import__(module)
app[web.1]: application = Cling(get_wsgi_application())
app[web.1]: AttributeError: 'module' object has no attribute 'Cling'
app[web.1]: application = Cling(get_wsgi_application())
What should I do with the Cling thing error? Is there anything I have missed while the project setup?
The error itself means that something is calling a method or getting an attribute on a python module instead of the class within the module.
This could happen if your module filename is the same as the class inside. Ie if you had cling.py and inside was a python class called cling.
Im not really up on python3 and I'm not sure whats causing this, I'm tempted to say it might be a circular dependency issue, or maybe one of the dependencies of dj-static ie static has been updated and caused this issue?
Maybe try to specify only dj-static in your requirements and remove the dependency on static as I believe dj-static should resolve its dependency on static by itself and that may be causing a conflict.
The documentation on heroku could be out of date.
I started using DjangoWhiteNoise instead of dj-static and no more problems.
In my case, I had an extraneous __init__.pyc in a subdirectory, where it shouldn't be. (Reason: as I moved modules around, the __init__.py was correctly deleted, but the compiled __init__.pyc had been left behind.)
Django's autodiscover then threw this error.
Deleting the unwanted __init__.pyc file fixed it.
I am trying to deploy my Django website onto Heroku but when I load my site, I get this error:
Application Error:
An error occurred in the application and your page could not be
served. Please try again in a few moments.
If you are the application owner, check your logs for details.
So I type heroku logs and this is what I got:
2015-02-20T15:49:36.361800+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
2015-02-20T15:49:36.361809+00:00 app[web.1]: return util.import_app(self.app_uri)
2015-02-20T15:49:36.361801+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-02-20T15:49:36.361803+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-02-20T15:49:36.361805+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-02-20T15:49:36.361808+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-02-20T15:49:36.361811+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-02-20T15:49:36.361815+00:00 app[web.1]: application = get_wsgi_application()
2015-02-20T15:49:36.361817+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
2015-02-20T15:49:36.361812+00:00 app[web.1]: __import__(module)
2015-02-20T15:49:36.361819+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
2015-02-20T15:49:36.361814+00:00 app[web.1]: File "/app/django_test/wsgi.py", line 14, in <module>
2015-02-20T15:49:36.361818+00:00 app[web.1]: django.setup()
2015-02-20T15:49:36.361823+00:00 app[web.1]: logging_config_func(logging_settings)
2015-02-20T15:49:36.361821+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2015-02-20T15:49:36.361822+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/log.py", line 87, in configure_logging
2015-02-20T15:49:36.361829+00:00 app[web.1]: '%r: %s' % (name, e))
2015-02-20T15:49:36.361830+00:00 app[web.1]: ValueError: Unable to configure handler 'default': [Errno 2] No such file or directory: '/app/logs/mylog.log'
2015-02-20T15:49:36.361929+00:00 app[web.1]: [2015-02-20 15:49:36 +0000] [9] [INFO] Worker exiting (pid: 9)
2015-02-20T15:49:36.361825+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/logging/config.py", line 794, in dictConfig
2015-02-20T15:49:36.361828+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/logging/config.py", line 576, in configure
2015-02-20T15:49:36.361826+00:00 app[web.1]: dictConfigClass(config).configure()
2015-02-20T15:49:36.488086+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker
2015-02-20T15:49:36.488087+00:00 app[web.1]: worker.init_process()
2015-02-20T15:49:36.488090+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-02-20T15:49:36.488092+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-02-20T15:49:36.488093+00:00 app[web.1]: self.callable = self.load()
2015-02-20T15:49:36.488089+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
2015-02-20T15:49:36.488103+00:00 app[web.1]: File "/app/django_test/wsgi.py", line 14, in <module>
2015-02-20T15:49:36.488099+00:00 app[web.1]: return util.import_app(self.app_uri)
2015-02-20T15:49:36.488100+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-02-20T15:49:36.488101+00:00 app[web.1]: __import__(module)
2015-02-20T15:49:36.488082+00:00 app[web.1]: [2015-02-20 15:49:36 +0000] [10] [ERROR] Exception in worker process:
2015-02-20T15:49:36.488076+00:00 app[web.1]: /app/static/
2015-02-20T15:49:36.488084+00:00 app[web.1]: Traceback (most recent call last):
2015-02-20T15:49:36.488106+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
2015-02-20T15:49:36.488108+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
2015-02-20T15:49:36.488131+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/logging/config.py", line 576, in configure
2015-02-20T15:49:36.488111+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/log.py", line 87, in configure_logging
2015-02-20T15:49:36.488113+00:00 app[web.1]: logging_config_func(logging_settings)
2015-02-20T15:49:36.488095+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-02-20T15:49:36.488133+00:00 app[web.1]: ValueError: Unable to configure handler 'default': [Errno 2] No such file or directory: '/app/logs/mylog.log'
2015-02-20T15:49:36.488140+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2015-02-20T15:49:36.488136+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker
2015-02-20T15:49:36.488096+00:00 app[web.1]: return self.load_wsgiapp()
2015-02-20T15:49:36.488141+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-02-20T15:49:36.488143+00:00 app[web.1]: self.callable = self.load()
2015-02-20T15:49:36.488097+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-02-20T15:49:36.488148+00:00 app[web.1]: return util.import_app(self.app_uri)
2015-02-20T15:49:36.488104+00:00 app[web.1]: application = get_wsgi_application()
2015-02-20T15:49:36.488153+00:00 app[web.1]: File "/app/django_test/wsgi.py", line 14, in <module>
2015-02-20T15:49:36.488110+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2015-02-20T15:49:36.488158+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
2015-02-20T15:49:36.488157+00:00 app[web.1]: django.setup()
2015-02-20T15:49:36.488160+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2015-02-20T15:49:36.488150+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-02-20T15:49:36.488107+00:00 app[web.1]: django.setup()
2015-02-20T15:49:36.488151+00:00 app[web.1]: __import__(module)
2015-02-20T15:49:36.488163+00:00 app[web.1]: logging_config_func(logging_settings)
2015-02-20T15:49:36.488114+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/logging/config.py", line 794, in dictConfig
2015-02-20T15:49:36.488132+00:00 app[web.1]: '%r: %s' % (name, e))
2015-02-20T15:49:36.488129+00:00 app[web.1]: dictConfigClass(config).configure()
2015-02-20T15:49:36.488164+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/logging/config.py", line 794, in dictConfig
2015-02-20T15:49:36.488165+00:00 app[web.1]: dictConfigClass(config).configure()
2015-02-20T15:49:36.488168+00:00 app[web.1]: '%r: %s' % (name, e))
2015-02-20T15:49:36.488139+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
2015-02-20T15:49:36.488135+00:00 app[web.1]: Traceback (most recent call last):
2015-02-20T15:49:36.488137+00:00 app[web.1]: worker.init_process()
2015-02-20T15:49:36.488167+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/logging/config.py", line 576, in configure
2015-02-20T15:49:36.507131+00:00 app[web.1]: super(Application, self).run()
2015-02-20T15:49:36.507076+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
2015-02-20T15:49:36.488146+00:00 app[web.1]: return self.load_wsgiapp()
2015-02-20T15:49:36.488144+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-02-20T15:49:36.507001+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-02-20T15:49:36.506915+00:00 app[web.1]: Traceback (most recent call last):
2015-02-20T15:49:36.506970+00:00 app[web.1]: sys.exit(run())
2015-02-20T15:49:36.507154+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
2015-02-20T15:49:36.507531+00:00 app[web.1]: self.reap_workers()
2015-02-20T15:49:36.507476+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 210, in handle_chld
2015-02-20T15:49:36.507269+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2015-02-20T15:49:36.488147+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-02-20T15:49:36.488154+00:00 app[web.1]: application = get_wsgi_application()
2015-02-20T15:49:36.488171+00:00 app[web.1]: [2015-02-20 15:49:36 +0000] [10] [INFO] Worker exiting (pid: 10)
2015-02-20T15:49:36.507190+00:00 app[web.1]: Arbiter(self).run()
2015-02-20T15:49:36.507453+00:00 app[web.1]: time.sleep(0.1)
2015-02-20T15:49:36.507056+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-02-20T15:49:36.507382+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 338, in stop
2015-02-20T15:49:36.507715+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-02-20T15:49:36.488161+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/log.py", line 87, in configure_logging
2015-02-20T15:49:36.488170+00:00 app[web.1]: ValueError: Unable to configure handler 'default': [Errno 2] No such file or directory: '/app/logs/mylog.log'
2015-02-20T15:49:36.507292+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 293, in halt
2015-02-20T15:49:36.507213+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 197, in run
2015-02-20T15:49:36.507642+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-02-20T15:49:36.507358+00:00 app[web.1]: self.stop()
2015-02-20T15:49:36.488155+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
2015-02-20T15:49:36.506923+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-02-20T15:49:36.507554+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 455, in reap_workers
2015-02-20T15:49:37.304329+00:00 heroku[web.1]: State changed from up to crashed
2015-02-20T15:49:37.292485+00:00 heroku[web.1]: Process exited with status 1
2015-02-20T15:49:36.299215+00:00 heroku[web.1]: State changed from starting to up
2015-02-20T15:49:42.613930+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=article-django.herokuapp.com request_id=5e18c64f-98b1-4f2b-a88b-c9d93a0908e9 fwd="173.3.238.36" dyno=web.1 connect=5001ms service= status=503 bytes=
I looked at this log and it seems like the main problem is something with '/app/logs/mylog.log' not existing. If that's the case, how I do I create that file?
Edit: Here is the LOGGING section of my settings.py file:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins':{
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'email_backend':
'django.core.mail.backends.filebased.EmailBackend',
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propogate': True,
},
}
}
/app is directory in which your application is put on Heroku. Try to add logs directory in root of your project and push it to Heroku - directory will then exist so log file should be created without problems.