【发布时间】:2017-02-15 10:47:56
【问题描述】:
我刚刚向我的 Django 应用程序添加了一个新应用程序,并且在本地一切正常。但是,当我推送 Heroku 时,尝试从新应用程序或与之相关的管理页面访问视图时出现以下错误。网站的其他部分运行良好。
错误(来自 heroku 应用程序日志):
2017-02-15T10:14:13.305769+00:00 app[web.1]: self.connection = connection_class(self.host, self.port, **connection_params)
2017-02-15T10:14:13.305769+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/smtplib.py", line 256, in __init__
2017-02-15T10:14:13.305770+00:00 app[web.1]: (code, msg) = self.connect(host, port)
2017-02-15T10:14:13.305770+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/smtplib.py", line 316, in connect
2017-02-15T10:14:13.305771+00:00 app[web.1]: self.sock = self._get_socket(host, port, self.timeout)
2017-02-15T10:14:13.305771+00:00 app[web.1]: return socket.create_connection((host, port), timeout)
2017-02-15T10:14:13.305771+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/smtplib.py", line 291, in _get_socket
2017-02-15T10:14:13.305772+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/socket.py", line 575, in create_connection
2017-02-15T10:14:13.305772+00:00 app[web.1]: raise err
2017-02-15T10:14:13.305773+00:00 app[web.1]: error: [Errno 111] Connection refused
设置
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ******
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = ['*']
ADMINS = (
(***, ***),
)
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'feed',
'cv',
'hon',
'blog',
'markdown_deux',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'Site.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 = 'Site.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =
dj_database_url.config(default=os.environ.get('DATABASE_URL'))
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Internationalization
# https://docs.djangoproject.com/en/1.8/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/1.8/howto/static-files/
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '../../feed/static/'),
)
我找不到太多有关此特定错误的文档,因此非常感谢任何帮助。怎么了?让我知道是否有更多信息可以提供帮助。
更新:关于前两个 cmets,我的“应用程序”是一个除了 django 管理后端之外的静态网站,我不会尝试在我的代码中的任何地方发送电子邮件。上面生成错误日志的页面只是一个简单博客的主页,列出了所有的帖子(目前没有,因为我无法添加任何帖子)。
【问题讨论】:
-
这是来自 smtplib,所以当您尝试发送电子邮件时可能会出现问题。您需要显示调用它的代码以及您的设置。
-
我同意 Daniel,您的回溯显示 smtplib 存在问题,发布您的设置或电子邮件发送代码
-
谢谢你们的帮助,我已经用请求的信息更新了问题。我不想在我的代码中的任何地方发送电子邮件,heroku/django 是否会出于某种原因这样做?我不相信我会在任何地方使用 smtplib。
-
是否有任何模块尝试保存到文件系统?
-
@NathanLoyer 不,我不知道。