doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.88k stars 355 forks source link

IndexError: pop from an empty deque running makemigrations #625

Open xuxoramos opened 2 years ago

xuxoramos commented 2 years ago

Running MongoDB on a remote AWS EC2 machine.

Running the makemigrations goal throws the following error:

pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}

However, right at the top, the trace says:

Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 1394, in _get_socket
    sock_info = self.sockets.popleft()
IndexError: pop from an empty deque

Tried solutions in #528 , but I guess they work when databases are local.

String connection is mongodb://<user>:<pass>@<aws_ec_2_hostname>:27017/denunciapaot?authSource=denunciapaot

Database denunciapaot does have this user, and the user has the proper permissions.

Snippet of my settings.py file:

import os

DATABASES = {
        'default': {
            'ENGINE': 'djongo',
            'NAME': 'denunciapaot',
            'ENFORCE_SCHEMA': False,
            'USER': os.getenv('MONGO_USR'),
            'PASSWORD': os.getenv('MONGO_PASSWD'),
            'CLIENT': {
                'host': 'mongodb://' + 
                os.getenv('MONGO_USR') + 
                ':' + 
                os.getenv('MONGO_PASSWD') +
                '@' + 
                os.getenv('MONGO_HOST')  + 
                ':' +
                os.getenv('MONGO_PORT') +
                '/' + 
                os.getenv('MONGO_DATABASE') + 
                '?authSource=denunciapaot'
            }  
        }
}

Python version is 3.6.9

My requirements.txt:

asgiref==3.2.3
Django==3.0.3
djangorestframework==3.11.0
djongo==1.3.6
django-cors-headers==3.10.1
pytz==2019.3
sqlparse==0.2.4
gunicorn==20.0.4
pymongo==3.12.1

Traceback

Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 1394, in _get_socket
    sock_info = self.sockets.popleft()
IndexError: pop from an empty deque

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 86, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations
    if self.has_table():
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
    return get_names(cursor)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/djongo/introspection.py", line 47, in get_table_list
    for c in cursor.db_conn.list_collection_names()
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/database.py", line 886, in list_collection_names
    for result in self.list_collections(session=session, **kwargs)]
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/database.py", line 849, in list_collections
    _cmd, read_pref, session)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1519, in _retryable_read
    read_pref, server, session) as (
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1371, in _secondaryok_for_server
    with self._get_socket(server, session) as sock_info:
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1309, in _get_socket
    self.__all_credentials, handler=err_handler) as sock_info:
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 1331, in get_socket
    sock_info = self._get_socket(all_credentials)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 1397, in _get_socket
    sock_info = self.connect(all_credentials)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 1297, in connect
    sock_info.check_auth(all_credentials)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 820, in check_auth
    self.authenticate(credentials)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 837, in authenticate
    auth.authenticate(credentials, self)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/auth.py", line 672, in authenticate
    auth_func(credentials, sock_info)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/auth.py", line 592, in _authenticate_default
    return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/auth.py", line 333, in _authenticate_scram
    res = sock_info.command(source, cmd)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/pool.py", line 721, in command
    exhaust_allowed=exhaust_allowed)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/network.py", line 163, in command
    parse_write_concern_error=parse_write_concern_error)
  File "/home/ubuntu/.virtualenvs/denunciapaot-env/lib/python3.6/site-packages/pymongo/helpers.py", line 167, in _check_command_response
    raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
kevinhuron commented 1 year ago

Hi,

Got exactly the same error...

Some help please ?

kevinhuron commented 1 year ago

Work for me when you put the config like this :

'mongodb': {
        'ENGINE': 'djongo',
        'ENFORCE_SCHEMA': False,
        'NAME': env('MONGO_DB_DATABASE'),
        'CLIENT': {
            'host': 'mongodb://{0}:{1}@{2}'.format(
                env('MONGO_DB_USERNAME'), env('MONGO_DB_PASSWORD'), env('MONGO_DB_HOST')
            ),
        },
    }