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

Not connecting to mongo DB #584

Open PeritusDev2 opened 2 years ago

PeritusDev2 commented 2 years ago

python version 3.6 requirement.txt

Django==3.2.6
gunicorn==20.1.0
pycodestyle==2.7.0
python-decouple==3.4
pytz==2021.1
sqlparse==0.2.3
toml==0.10.2
Unipath==1.1
whitenoise==5.3.0
django-debug-toolbar>=2.2
tldextract
django-crispy-forms
djongo

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'sample',
        'ENFORCE_SCHEMA': False,
        'CLIENT': {
                'host': 'mongodb://user:password@ingestion-store:27017',
                'username': 'user',
                'password': 'password',
                'authSource': 'sample',
                'authMechanism': 'SCRAM-SHA-1'
        }
    }
}

Traceback

Traceback (most recent call last):
  File "ingestion-dashboard/manage.py", line 22, in <module>
    main()
  File "ingestion-dashboard/manage.py", line 19, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 92, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 53, in __init__
    self.build_graph()
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 220, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
    if self.has_table():
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    tables = self.connection.introspection.table_names(cursor)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 52, in table_names
    return get_names(cursor)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/introspection.py", line 47, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/usr/local/lib/python3.6/site-packages/djongo/introspection.py", line 47, in get_table_list
    for c in cursor.db_conn.list_collection_names()
  File "/usr/local/lib/python3.6/site-packages/pymongo/database.py", line 880, in list_collection_names
    for result in self.list_collections(session=session, **kwargs)]
  File "/usr/local/lib/python3.6/site-packages/pymongo/database.py", line 843, in list_collections
    _cmd, read_pref, session)
  File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1515, in _retryable_read
    read_pref, session, address=address)
  File "/usr/local/lib/python3.6/site-packages/pymongo/mongo_client.py", line 1346, in _select_server
    server = topology.select_server(server_selector)
  File "/usr/local/lib/python3.6/site-packages/pymongo/topology.py", line 246, in select_server
    address))
  File "/usr/local/lib/python3.6/site-packages/pymongo/topology.py", line 203, in select_servers
    selector, server_timeout, address)
  File "/usr/local/lib/python3.6/site-packages/pymongo/topology.py", line 220, in _select_servers_loop
    (self._error_message(selector), timeout, self.description))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 61a8fe6f099230e150fbbfed, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused',)>]>
Uysim commented 1 year ago

Did anyone solve this problem? Why it keep connecting to 127.0.0.1 even I specific host in CLIENT options?