繁体   English   中英

尝试访问 Django 页面时,在 Heroku 上部署了 Django 应用程序时出现错误代码 H13

[英]Error code H13 with Django App deployed on Heroku when trying to access Django page

我的网站和管理页面在本地工作,但在尝试访问 Heroku 网页上的管理页面时出现应用程序错误:H13。

这是heroku日志的一部分:

[web.1]: 10.47.180.171 - - [29/Feb/2020:21:10:30 +0000] "GET /favicon.ico HTTP/1.1" 404 179 "https://quiet-woodland-94985.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"
2020-02-29T21:18:46.170318+00:00 app[web.1]: [2020-02-29 21:18:46 +0000] [13] [INFO] Booting worker with pid: 13
2020-02-29T21:18:46.166523+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/admin/" host=quiet-woodland-94985.herokuapp.com request_id=43137702-84dc-4892-b3bf-9c0c6d155a6b fwd="174.55.195.195" dyno=web.1 connect=1ms service=67ms status=503 bytes=0 protocol=https
2020-02-29T21:18:56.996229+00:00 app[api]: Set DJANGO_ADMIN_URL config vars by user phikhant@uci.edu
2020-02-29T21:18:56.996229+00:00 app[api]: Release v22 created by user phikhant@uci.edu
2020-02-29T21:18:57.341490+00:00 heroku[web.1]: Restarting
2020-02-29T21:18:57.344662+00:00 heroku[web.1]: State changed from up to starting
2020-02-29T21:18:58.324719+00:00 app[web.1]: [2020-02-29 21:18:58 +0000] [13] [INFO] Worker exiting (pid: 13)[2020-02-29 21:18:58 +0000] [12] [INFO] Worker exiting (pid: 12)
2020-02-29T21:18:58.324729+00:00 app[web.1]:
2020-02-29T21:18:58.324730+00:00 app[web.1]: [2020-02-29 21:18:58 +0000] [4] [INFO] Handling signal: term
2020-02-29T21:18:58.420449+00:00 app[web.1]: [2020-02-29 21:18:58 +0000] [4] [INFO] Shutting down: Master
2020-02-29T21:18:58.304389+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-02-29T21:18:58.508719+00:00 heroku[web.1]: Process exited with status 0
2020-02-29T21:19:01.612316+00:00 heroku[web.1]: Starting process with command `gunicorn TreatmentPlanning.wsgi --log-file -`
2020-02-29T21:19:03.436411+00:00 app[web.1]: [2020-02-29 21:19:03 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-02-29T21:19:03.436964+00:00 app[web.1]: [2020-02-29 21:19:03 +0000] [4] [INFO] Listening at: http://0.0.0.0:59479 (4)
2020-02-29T21:19:03.437062+00:00 app[web.1]: [2020-02-29 21:19:03 +0000] [4] [INFO] Using worker: sync
2020-02-29T21:19:03.441089+00:00 app[web.1]: [2020-02-29 21:19:03 +0000] [10] [INFO] Booting worker with pid: 10
2020-02-29T21:19:03.500564+00:00 app[web.1]: [2020-02-29 21:19:03 +0000] [11] [INFO] Booting worker with pid: 11
2020-02-29T21:19:03.877103+00:00 heroku[web.1]: State changed from starting to up
2020-02-29T21:19:06.855573+00:00 app[web.1]: [2020-02-29 21:19:06 +0000] [12] [INFO] Booting worker with pid: 12
2020-02-29T21:19:06.852571+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/admin/" host=quiet-woodland-94985.herokuapp.com request_id=ba1359d8-8365-4e35-bc10-93f902e33ee5 fwd="174.55.195.195" dyno=web.1 connect=1ms service=117ms status=503 bytes=0 protocol=https
2020-02-29T21:21:16.208007+00:00 app[api]: Starting process with command `bash` by user phikhant@uci.edu
2020-02-29T21:21:22.007938+00:00 heroku[run.3168]: State changed from starting to up
2020-02-29T21:21:22.178709+00:00 heroku[run.3168]: Awaiting client
2020-02-29T21:21:22.214591+00:00 heroku[run.3168]: Starting process with command `bash`
2020-02-29T21:21:58.055564+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/admin/" host=quiet-woodland-94985.herokuapp.com request_id=b67d0ddd-d88d-4c39-9cca-15c27ea7cc16 fwd="174.55.195.195" dyno=web.1 connect=1ms service=106ms status=503 bytes=0 protocol=https
2020-02-29T21:21:58.058202+00:00 app[web.1]: [2020-02-29 21:21:58 +0000] [13] [INFO] Booting worker with pid: 13
2020-02-29T21:22:00.518484+00:00 heroku[router]: at=info method=GET path="/" host=quiet-woodland-94985.herokuapp.com request_id=b8f0acaf-c2f4-4260-82cf-5f900673d1c7 fwd="174.55.195.195" dyno=web.1 connect=1ms service=63ms status=200 bytes=4899 protocol=https
2020-02-29T21:22:00.511031+00:00 app[web.1]: 10.30.127.176 - - [29/Feb/2020:21:22:00 +0000] "GET / HTTP/1.1" 200 4681 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"
2020-02-29T21:22:02.627781+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/admin/" host=quiet-woodland-94985.herokuapp.com request_id=f722da7b-00d9-46e7-9e78-20d1e098d11c fwd="174.55.195.195" dyno=web.1 connect=1ms service=95ms status=503 bytes=0 protocol=https
2020-02-29T21:22:02.631308+00:00 app[web.1]: [2020-02-29 21:22:02 +0000] [14] [INFO] Booting worker with pid: 14
2020-02-29T21:22:04.932431+00:00 heroku[run.3168]: Client connection closed. Sending SIGHUP to all processes
2020-02-29T21:22:05.499704+00:00 heroku[run.3168]: State changed from up to complete
2020-02-29T21:22:05.483859+00:00 heroku[run.3168]: Process exited with status 129

这是我的requirements.txt文件:

asgiref==3.2.3
dj-database-url==0.5.0
Django==3.0.3
django-heroku==0.3.1
gunicorn==20.0.4
psycopg2==2.8.4
pytz==2019.3
sqlparse==0.3.0
whitenoise==5.0.1
psycopg2-binary==2.8.4

这是我的 procfile

web: gunicorn TreatmentPlanning.wsgi --log-file -

编辑:

在四处寻找时,我发现此应用程序错误仅在登录后才会出现。django 管理登录页面仍然正常运行。

设置.py:

"""
Django settings for TreatmentPlanning project.

Generated by 'django-admin startproject' using Django 3.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os
import django_heroku

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['DJANGO_SECRET_KEY']


# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True
DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False'

ALLOWED_HOSTS = ['quiet-woodland-94985.herokuapp.com' , '127.0.0.1']


# Application definition

INSTALLED_APPS = [
    'treatment_plan.apps.TreatmentPlanConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'TreatmentPlanning.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 = 'TreatmentPlanning.wsgi.application'


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

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


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Heroku: Update database configuration from $DATABASE_URL.
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

# The absolute path to the directory where collectstatic will collect static files for deployment.
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# The URL to use when referring to static files (where they will be served from)
STATIC_URL = '/static/'

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

django_heroku.settings(locals())

项目文件夹中的 url.py

"""TreatmentPlanning URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include("treatment_plan.urls")),
]

在尝试部署按照MDN 文档创建的应用程序时遇到了同样的问题。 能够通过将 Django 版本降低到 2.2.10 来解决它。 这是requirements.txt文件,部署的应用程序在本地运行。 如果您不是专门出于某种目的使用 Django 3,那么将其降低到 2.2.10 应该没问题。 MDN 上的教程也是使用 django 2 制作的。

也有这个错误。 不是由于超时,因为它立即出现。 我刚刚对 requirements.txt 进行了更改,包括更新了一些软件包的版本。 当我在 Github 上时,我将 requirements.txt 文件回滚到以前的版本,从而解决了这个问题。 我的猜测是您的需求文件导致了问题(尽管很难将其中的特定行与错误隔离开来)。

我认为这个错误与超时有关。 这个解释在 Heroku 页面中被引用为 H13 错误。 “可能发生这种情况的一个例子是,当 Unicorn Web 服务器配置的超时时间短于 30 秒,并且在超时发生之前,工作人员尚未处理请求。在这种情况下,Unicorn 在写入任何数据之前关闭连接,导致 H13。”

所以我认为这个回复可以帮助你解决你的问题。 https://stackoverflow.com/a/28336729/7938870

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM