mathiasertl / django-ca

Django app providing a Certificate Authority
GNU General Public License v3.0
145 stars 43 forks source link

ACME error #101

Closed raydoom closed 1 year ago

raydoom commented 1 year ago
[pid: 16|app: 0|req: 33/196] 172.16.0.198 () {36 vars in 667 bytes} [Mon Jun 12 09:37:43 2023] HEAD /django_ca/acme/3888B72A41A491648433888E61D5EB8D58AE72E6/new-nonce/ => generated 145 bytes in 224 msecs (HTTP/1.1 500) 7 headers in 240 bytes (1 switches on core 0)
[pid: 16|app: 0|req: 34/197] 172.16.0.198 () {36 vars in 590 bytes} [Mon Jun 12 09:38:29 2023] GET /django_ca/acme/directory/ => generated 590 bytes in 34 msecs (HTTP/1.1 200) 6 headers in 199 bytes (1 switches on core 1)
[ERROR    2023-06-12 09:38:31] Internal Server Error: /django_ca/acme/3888B72A41A491648433888E61D5EB8D58AE72E6/new-nonce/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 1435, in get_connection
    connection = self._available_connections.pop()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: pop from empty list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/django-ca/ca/django_ca/acme/views.py", line 498, in dispatch
    response["replay-nonce"] = self.get_nonce()
                               ^^^^^^^^^^^^^^^^
  File "/usr/src/django-ca/ca/django_ca/acme/views.py", line 212, in get_nonce
    cache.set(self.get_cache_key(nonce), 0)
  File "/usr/local/lib/python3.11/site-packages/django/core/cache/backends/redis.py", line 191, in set
    self._cache.set(key, value, self.get_backend_timeout(timeout))
  File "/usr/local/lib/python3.11/site-packages/django/core/cache/backends/redis.py", line 108, in set
    client.set(key, value, ex=timeout)
  File "/usr/local/lib/python3.11/site-packages/redis/commands/core.py", line 2302, in set
    return self.execute_command("SET", *pieces, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/redis/client.py", line 1255, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 1437, in get_connection
    connection = self.make_connection()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 1477, in make_connection
    return self.connection_class(**self.connection_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/redis/connection.py", line 941, in __init__
    super().__init__(**kwargs)
TypeError: AbstractConnection.__init__() got an unexpected keyword argument 'DB'
mathiasertl commented 1 year ago

The traceback indicates it cannot access the redid cache. How did you install Django-ca, what version, which Python version? And in this case, what redis version are you using?

raydoom commented 1 year ago

I use docker ,follow the doc from https://django-ca.readthedocs.io/en/latest/docker.html

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND                  CREATED        STATUS        PORTS                                                                                                                                                                                                                                                                                                                                                                                                                   NAMES
52ef60f773a9   redis                   "docker-entrypoint.s…"   18 hours ago   Up 18 hours   6379/tcp                                                                                                                                                                                                                                                                                                                                                                                                                redis
85cae7d1a3e1   nginx                   "/docker-entrypoint.…"   19 hours ago   Up 19 hours   0.0.0.0:80->80/tcp, :::80->80/tcp                                                                                                                                                                                                                                                                                                                                                                                       nginx
fb231e423bcd   mathiasertl/django-ca   "/bin/sh -c ./uwsgi.…"   19 hours ago   Up 19 hours   8000/tcp                                                                                                                                                                                                                                                                                                                                                                                                                frontend
d6a843d71b68   mathiasertl/django-ca   "./celery.sh"            19 hours ago   Up 19 hours   8000/tcp                                                                                                                                                                                                                                                                                                                                                                                                                backend
5b1ca4eaf8ea   postgres                "docker-entrypoint.s…"   19 hours ago   Up 19 hours   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp                                                                                                                                                                                                                                                                                                                                                                               postgres

and I run a redis-cli in django-ca network,it connect to redis successfully.

[root@07ff743e49b0 /]# redis-cli -h redis
redis:6379> info
# Server
redis_version:7.0.11
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:5c712dc4cb9cfb70
redis_mode:standalone
os:Linux 4.18.0-425.13.1.el8_7.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:10.2.1
process_id:1
process_supervised:no
run_id:a0e0ad0bd064b3573034d85dbaa059abcf799272
tcp_port:6379
server_time_usec:1686620120404552
uptime_in_seconds:64491
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:8898520
executable:/data/redis-server
config_file:
io_threads_active:0
mathiasertl commented 1 year ago

Hi @raydoom ,

I found the problem: There is a mistake in the documentation, the DB value should be db. Change localsettings.yaml like this:

  CACHES:
      default:
          BACKEND: django.core.cache.backends.redis.RedisCache
          LOCATION: redis://redis:6379
          OPTIONS:
-             DB: "1"
+             db: "1"

  # django-ca will use Celery as an asynchronous task worker
  CELERY_BROKER_URL: redis://redis:6379/0

This should solve the problem!

I also just added a test script to test that everything can connect properly, making such mistakes impossible in the future. :-)

kr, Mat

mathiasertl commented 1 year ago

@raydoom I think the issue is solved. If you still have issues with connecting to redis, please comment here. If you experience other issues, please don't hesitate to create a new issue!

I'll leave this issue open for a week unless there is negative feedback, please feel free to close the issue if everything works for you.

kr, Mat

raydoom commented 1 year ago

it work ,thanks