将Django代码部署到Heroku时出现错误代码H10

时间:2020-08-11 15:54:51

标签: python django heroku deployment gunicorn

将Django应用程序部署到Heroku时遇到很多麻烦。我是Django和Heroku的新手,我无法理解回溯告诉我的内容。 我在heroku日志回溯中不断收到错误代码“ h10”。我相信Gunicorn无法正常启动,但我不知道解决方案。我还搜索了这个问题数小时,并重写了Procfile,重新安装gunicorn,virtualenv,django-heroku等对我没有用。

我看不到我的错误是什么。当我运行heroku logs --tail时,我看到:

(--sliced to view gunicorn issue--)
2020-08-11T15:30:05.149176+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-08-11T15:30:05.149958+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [4] [DEBUG] Arbiter booted
2020-08-11T15:30:05.150076+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [4] [INFO] Listening at: http://0.0.0.0:46142 (4)
2020-08-11T15:30:05.150185+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [4] [INFO] Using worker: sync
2020-08-11T15:30:05.155860+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [10] [INFO] Booting worker with pid: 10
2020-08-11T15:30:05.164169+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [10] [ERROR] Exception in worker process
2020-08-11T15:30:05.164171+00:00 app[web.1]: Traceback (most recent call last):
2020-08-11T15:30:05.164172+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-08-11T15:30:05.164172+00:00 app[web.1]: worker.init_process()
2020-08-11T15:30:05.164173+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-08-11T15:30:05.164174+00:00 app[web.1]: self.load_wsgi()
2020-08-11T15:30:05.164174+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-08-11T15:30:05.164174+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-08-11T15:30:05.164175+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-08-11T15:30:05.164175+00:00 app[web.1]: self.callable = self.load()
2020-08-11T15:30:05.164176+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-08-11T15:30:05.164176+00:00 app[web.1]: return self.load_wsgiapp()
2020-08-11T15:30:05.164177+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-08-11T15:30:05.164177+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-08-11T15:30:05.164178+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-08-11T15:30:05.164178+00:00 app[web.1]: mod = importlib.import_module(module)
2020-08-11T15:30:05.164179+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-08-11T15:30:05.164179+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-08-11T15:30:05.164180+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-08-11T15:30:05.164180+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-08-11T15:30:05.164180+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
2020-08-11T15:30:05.164186+00:00 app[web.1]: ModuleNotFoundError: No module named 'scholarstarterapp.wsgi'
2020-08-11T15:30:05.164438+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-08-11T15:30:05.212254+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [4] [INFO] Shutting down: Master
2020-08-11T15:30:05.212403+00:00 app[web.1]: [2020-08-11 15:30:05 +0000] [4] [INFO] Reason: Worker failed to boot.
2020-08-11T15:30:05.325066+00:00 heroku[web.1]: Process exited with status 3
2020-08-11T15:30:05.382253+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-11T15:32:16.258158+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=scholarstarterapp.herokuapp.com request_id=585ca89d-e578-49d1-ad4c-3626ed289e76 fwd="68.227.124.46" dyno= connect= service= status=503 bytes= protocol=https
2020-08-11T15:32:16.392639+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=scholarstarterapp.herokuapp.com request_id=6409d9cb-3263-450a-a458-700fb6cb012b fwd="68.227.124.46" dyno= connect= service= status=503 bytes= protocol=https

我的settings.py如下:

import logging
import os
import django_heroku

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

SITE_ID=1
if DEBUG:
    # will output to your console
    logging.basicConfig(
        level = logging.DEBUG,
        format = '%(asctime)s %(levelname)s %(message)s',
    )
else:
    # will output to logging file
    logging.basicConfig(
        level = logging.DEBUG,
        format = '%(asctime)s %(levelname)s %(message)s',
        filename = '/logfile.log',
        filemode = 'a'
    )

ALLOWED_HOSTS = [ 'https://scholarstarterapp.herokuapp.com/' ]

if DEBUG:
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' #during development - update on deployment

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.flatpages',
   # 'regwall',

    # 3rd party
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'debreach',
    'ckeditor',
    'ckeditor_uploader',

    # authentication
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.facebook',
    
     #----------(I've cut out my local app configs here)---
    'formtools',
    'send',
    'crispy_forms',
    'bootstrap4',
    'djstripe',
    'bootstrap_modal_forms',
]

MIDDLEWARE = [
    

    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.gzip.GZipMiddleware',
    'debreach.middleware.RandomCommentMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
]

ROOT_URLCONF = 'scholarstarterapp.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'scholarstarterapp.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.postgresql',
#        'NAME': 'buoeirnx',
#        'USER': 'buoeirnx',
#        'PASSWORD': 'lWdGUjsieyc5LocCEiZispUMIoLk5yzV',
#        'HOST':'ruby.db.elephantsql.com',
#        'PORT': '5432'
#    }
#}

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

PROJECT_DIR = os.path.dirname(__file__)

MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')

MEDIA_URL = '/media/'
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_IMAGE_BACKEND="pillow"

CKEDITOR_CONFIGS = {
    'article_config': {
        'toolbar': 'Special',
        'toolbar_Special': [
            {'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize', '-', 'Maximize', 'ShowBlocks']},
            '/',
            {'name': 'basicstyles',
             'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']},
            {'name': 'clipboard', 'items': ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']},
            {'name': 'paragraph',
             'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-',
                       'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']},
            {'name': 'links', 'items': ['Link', 'Unlink']},
            {'name': 'insert',
             'items': ['Image', 'Table', 'HorizontalRule', 'Iframe', 'Youtube']},
        ],
        'extraPlugins': ','.join(['youtube'])
    }
}

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
MEDIA_URL = '/images/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')

if os.getcwd() == '/app':
    DEBUG=True
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
    SECURE_SSL_REDIRECT = True


STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Password validation
# https://docs.djangoproject.com/en/2.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/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Chicago'

USE_I18N = True

USE_L10N = True

USE_TZ = True

AUTH_USER_MODEL = 'users.CustomUser'

LOGIN_REDIRECT_URL = 'dashboard'
LOGOUT_REDIRECT_URL = 'home'

#AUTHENTICATION_BACKENDS = ['users.forms.EmailBackend']

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",

    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
)

SITE_ID = 1

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_UNIQUE_EMAIL = True

SOCIALACCOUNT_QUERY_EMAIL=ACCOUNT_EMAIL_REQUIRED
SOCIALACCOUNT_EMAIL_REQUIRED=ACCOUNT_EMAIL_REQUIRED
SOCIALACCOUNT_STORE_TOKENS=False

SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'METHOD': 'oauth2',
        'SCOPE': ['email', 'public_profile', 'user_friends'],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'INIT_PARAMS': {'cookie': True},
        'FIELDS': [
            'id',
            'email',
            'name',
            'first_name',
            'last_name',
            'verified',
            'locale',
            'timezone',
            'link',
            'gender',
            'updated_time',
        ],
        'EXCHANGE_TOKEN': True,
        'LOCALE_FUNC': 'path.to.callable',
        'VERIFIED_EMAIL': False,
        'VERSION': 'v2.12',
    },
     'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        }
    }
}

ACCOUNT_FORMS = {'signup': 'users.forms.CustomSignupForm'}

# Configure django app for heroku.
django_heroku.settings(locals())

我的procfile看起来像:

web: gunicorn scholarstarterapp.wsgi:application --log-file - --log-level debug
python manage.py collectstatic --noinput
manage.py migrate

如果您知道我的错误意思,请告诉我!

1 个答案:

答案 0 :(得分:0)

将其放在此处以供将来参考,因为我已经解决了问题。

我的“ settings.py”,“ wsgi.py”等未存储在名为“ scholarstarterapp”的文件中。他们在“ scholarstarterappmaster”中

我编辑了wsgi.py文件,proc文件和settings.py文件,以反映“ scholarstarterappmaster”文件夹的名称,并且部署是干净的。

确保您知道引用的文件名!