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:
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. 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
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:
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
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.