Unable to load the web interface with a sentinel redis : Exception Type: ImproperlyConfigured at / #5325

Closed
opened 2025-12-29 19:26:38 +01:00 by adam · 4 comments
Owner

Originally created by @pierrechev on GitHub (Sep 6, 2021).

Originally assigned to: @pierrechev on GitHub.

NetBox version

v3.0.1

Python version

3.9

Steps to Reproduce

  1. Configure netbox to use a redis sentinel (https://netbox.readthedocs.io/en/stable/configuration/required-settings/ : Using Redis Sentinel)
  2. Start netbox
  3. Try to connect to the main url to netbox https://localhost:12345/
  4. Error

Logs :

Request Method: GET
Request URL: http://localhost:12345/
Django Version: 3.2.7
Python Version: 3.9.7
Installed Applications:
['django.contrib.admin',
-----
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/__init__.py", line 136, in get
    latest_release = cache.get('latest_release')
  File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 91, in get
    value = self._get(key, default, version, client)
  File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 31, in _decorator
    return method(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 98, in _get
    return self.client.get(key, default=default, version=version, client=client)
  File "/usr/local/lib/python3.9/site-packages/django_redis/client/default.py", line 253, in get
    client = self.get_client(write=False)
  File "/usr/local/lib/python3.9/site-packages/django_redis/client/default.py", line 105, in get_client
    self._clients[index] = self.connect(index)
  File "/usr/local/lib/python3.9/site-packages/django_redis/client/sentinel.py", line 36, in connect
    raise ImproperlyConfigured(

Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/
Exception Value: Settings DJANGO_REDIS_CONNECTION_FACTORY or CACHE[].OPTIONS.CONNECTION_POOL_CLASS is not configured correctly.

Expected Behavior

We have this issue because the variable DJANGO_REDIS_CONNECTION_FACTORY is not set in settings.py (https://github.com/netbox-community/netbox/blob/master/netbox/netbox/settings.py)

fix :

if CACHING_REDIS_SENTINELS:
    DJANGO_REDIS_CONNECTION_FACTORY = 'django_redis.pool.SentinelConnectionFactory'
    CACHES['default']['LOCATION'] = f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_SENTINEL_SERVICE}/{CACHING_REDIS_DATABASE}'
    CACHES['default']['OPTIONS']['CLIENT_CLASS'] = 'django_redis.client.SentinelClient'
    CACHES['default']['OPTIONS']['SENTINELS'] = CACHING_REDIS_SENTINELS
if CACHING_REDIS_SKIP_TLS_VERIFY:
    CACHES['default']['OPTIONS']['CONNECTION_POOL_KWARGS']['ssl_cert_reqs'] = False

Observed Behavior

Originally created by @pierrechev on GitHub (Sep 6, 2021). Originally assigned to: @pierrechev on GitHub. ### NetBox version v3.0.1 ### Python version 3.9 ### Steps to Reproduce 1. Configure netbox to use a redis sentinel (https://netbox.readthedocs.io/en/stable/configuration/required-settings/ : Using Redis Sentinel) 2. Start netbox 3. Try to connect to the main url to netbox https://localhost:12345/ 4. Error Logs : ``` Request Method: GET Request URL: http://localhost:12345/ Django Version: 3.2.7 Python Version: 3.9.7 Installed Applications: ['django.contrib.admin', ----- Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "/opt/netbox/netbox/netbox/views/__init__.py", line 136, in get latest_release = cache.get('latest_release') File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 91, in get value = self._get(key, default, version, client) File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 31, in _decorator return method(self, *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 98, in _get return self.client.get(key, default=default, version=version, client=client) File "/usr/local/lib/python3.9/site-packages/django_redis/client/default.py", line 253, in get client = self.get_client(write=False) File "/usr/local/lib/python3.9/site-packages/django_redis/client/default.py", line 105, in get_client self._clients[index] = self.connect(index) File "/usr/local/lib/python3.9/site-packages/django_redis/client/sentinel.py", line 36, in connect raise ImproperlyConfigured( Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/ Exception Value: Settings DJANGO_REDIS_CONNECTION_FACTORY or CACHE[].OPTIONS.CONNECTION_POOL_CLASS is not configured correctly. ``` ### Expected Behavior We have this issue because the variable DJANGO_REDIS_CONNECTION_FACTORY is not set in settings.py (https://github.com/netbox-community/netbox/blob/master/netbox/netbox/settings.py) fix : ``` if CACHING_REDIS_SENTINELS: DJANGO_REDIS_CONNECTION_FACTORY = 'django_redis.pool.SentinelConnectionFactory' CACHES['default']['LOCATION'] = f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_SENTINEL_SERVICE}/{CACHING_REDIS_DATABASE}' CACHES['default']['OPTIONS']['CLIENT_CLASS'] = 'django_redis.client.SentinelClient' CACHES['default']['OPTIONS']['SENTINELS'] = CACHING_REDIS_SENTINELS if CACHING_REDIS_SKIP_TLS_VERIFY: CACHES['default']['OPTIONS']['CONNECTION_POOL_KWARGS']['ssl_cert_reqs'] = False ``` ### Observed Behavior -
adam added the type: bugstatus: accepted labels 2025-12-29 19:26:38 +01:00
adam closed this issue 2025-12-29 19:26:38 +01:00
Author
Owner

@AvdeevArtem commented on GitHub (Sep 6, 2021):

We've same problem

@AvdeevArtem commented on GitHub (Sep 6, 2021): We've same problem
Author
Owner

@jeremystretch commented on GitHub (Sep 7, 2021):

  1. Try to connect to the main url to netbox https://localhost:12345/

Why are you accessing the NetBox interface on port 12345? That's very unusual.

Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/

Where did his URL come from? It's not a NetBox URL.

@jeremystretch commented on GitHub (Sep 7, 2021): > 3. Try to connect to the main url to netbox https://localhost:12345/ Why are you accessing the NetBox interface on port 12345? That's very unusual. > Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/ Where did his URL come from? It's not a NetBox URL.
Author
Owner

@pierrechev commented on GitHub (Sep 7, 2021):

  1. Try to connect to the main url to netbox https://localhost:12345/

Why are you accessing the NetBox interface on port 12345? That's very unusual.

Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/

Where did his URL come from? It's not a NetBox URL.

Sorry for this, i replaced my own port, but i have the issue on port 443 too :)

@pierrechev commented on GitHub (Sep 7, 2021): > > 1. Try to connect to the main url to netbox https://localhost:12345/ > > Why are you accessing the NetBox interface on port 12345? That's very unusual. > > > Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/ > > Where did his URL come from? It's not a NetBox URL. Sorry for this, i replaced my own port, but i have the issue on port 443 too :)
Author
Owner

@jeremystretch commented on GitHub (Sep 7, 2021):

Thanks for the PR @pierrechev!

@jeremystretch commented on GitHub (Sep 7, 2021): Thanks for the PR @pierrechev!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5325