简体   繁体   English

Django Heroku,服务器不支持 SSL,但需要 SSL

[英]Django Heroku, server does not support SSL, but SSL was required

I have a Django application deployed to Heroku and Postgres, I'm trying to add pgbouncer to scale the app a bit, but I'm getting this error:我有一个部署到 Heroku 和 Postgres 的 Django 应用程序,我正在尝试添加 pgbouncer 以稍微扩展应用程序,但出现此错误:

django.db.utils.OperationalError: server does not support SSL, but SSL was required

as a lot of other questions say, the problem is the SSL in django-heroku package.正如许多其他问题所说,问题在于 django-heroku 包中的 SSL。 So I tried to approaches, first: adding to the end of setting file the following:所以我尝试接近,首先:在设置文件的末尾添加以下内容:

del DATABASES['default']['OPTIONS']['sslmode']

the error is still being raised, so I took django-heroku settings function and modified it to disable SSL directly in there该错误仍在引发,因此我采用了 django-heroku 设置功能并对其进行了修改以直接在那里禁用 SSL

def custom_settings(config, *, db_colors=False, databases=True, test_runner=True, staticfiles=True, allowed_hosts=True,
             logging=True, secret_key=True):
    # Database configuration.
    # TODO: support other database (e.g. TEAL, AMBER, etc, automatically.)
    # Same code as the package
    # CHANGING SSL TO FALSE
                    config['DATABASES'][db_color] = dj_database_url.parse(url, conn_max_age=MAX_CONN_AGE,
                                                                          ssl_require=False)
 
        if 'DATABASE_URL' in os.environ:
            logger.info('Adding $DATABASE_URL to default DATABASE Django setting.')

            # Configure Django for DATABASE_URL environment variable.
            config['DATABASES']['default'] = dj_database_url.config(conn_max_age=MAX_CONN_AGE, ssl_require=False)

            logger.info('Adding $DATABASE_URL to TEST default DATABASE Django setting.')

and calling it:并调用它:

django_heroku_override.custom_settings(config=locals(), staticfiles=False, logging=False)

but that didn't work as well, I'm still getting the original error但这并没有奏效,我仍然收到原始错误

adding Procfile just for complicity:添加 Procfile 只是为了同谋:

web: bin/start-pgbouncer daphne rivendell.asgi:application --port $PORT --bind 0.0.0.0 -v2
worker: python manage.py runworker channel_layer -v2

I solved this problem by changing this in settings.py我通过在 settings.py 中更改它解决了这个问题

db_from_env = dj_database_url.config(conn_max_age=0)
django_heroku.settings(locals())

to

db_from_env = dj_database_url.config(conn_max_age=0, ssl_require=False)
django_heroku.settings(locals() ,databases=False)

This worked for me because setting databases=false disallowed to use heroku default database configuration and allowed to pass ssl_require=false which I set!这对我有用,因为设置databases=false不允许使用 heroku 默认数据库配置并允许传递我设置的ssl_require=false

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

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