如何解决' [Errno 111]连接被拒绝'在Heroku上的Django应用程序?

时间:2017-02-15 10:47:56

标签: django heroku

我刚刚在我的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/'),
)

我无法找到有关此特定错误的大量文档,因此我们非常感谢您提供帮助。出了什么问题?如果我能提供更多可以提供帮助的信息,请告诉我。

更新:关于前两条评论,我的应用程序'是一个静态网站,除了django管理员后端,我没有尝试在我的代码中的任何地方发送电子邮件。生成上述错误日志的页面只是一个简单博客的主页,列出了所有帖子(目前没有帖子,因为我无法添加任何帖子)。

1 个答案:

答案 0 :(得分:0)

我不确定原因是什么,但是这个问题在我对其中一个文件进行虚拟更改(在一行末尾添加一个空格)之后解决了,并将应用程序重新推送到Heroku