gpt4 book ai didi

django - pymongo.errors.OperationFailure : Authentication failed

转载 作者:行者123 更新时间:2023-12-04 15:46:31 25 4
gpt4 key购买 nike

我正在尝试在 Django 中使用 MongoDB 数据库。为此,我将我的设置更改为此,我在这里使用 mlab。

settings.py

DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'crud-django',
'HOST': 'mongodb://adityakmr:password1@ds231956.mlab.com:31956/',
'USER': 'adityakmr',
'PASSWORD': 'password1'
}
}

但每次我尝试运行迁移时,我都会遇到这样的错误。我不知道它来自哪里我已经提供了正确的用户名和密码。我还使用 pip 安装了 djongo。

Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\core\management\commands\migrate.py", line 87, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\db\migrations\loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\db\migrations\recorder.py", line 73, in applied_migrations
if self.has_table():
File "C:\Users\adity\Desktop\crud-django\env\lib\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 "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\django\db\backends\base\introspection.py", line 48, in table_names
return get_names(cursor)
File "C:\Users\adity\Desktop\crud-django\env\lib\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 "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\djongo\introspection.py", line 46, in get_table_list
for c in cursor.db_conn.collection_names(False)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\database.py", line 715, in collection_names
nameOnly=True, **kws)]
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\database.py", line 674, in list_collections
read_pref) as (sock_info, slave_okay):
File "c:\users\adity\appdata\local\programs\python\python37-32\Lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\mongo_client.py", line 1101, in _socket_for_reads
with self._get_socket(server) as sock_info:
File "c:\users\adity\appdata\local\programs\python\python37-32\Lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\mongo_client.py", line 1058, in _get_socket
with server.get_socket(self.__all_credentials) as sock_info:
File "c:\users\adity\appdata\local\programs\python\python37-32\Lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\pool.py", line 1006, in get_socket
sock_info.check_auth(all_credentials)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\pool.py", line 677, in check_auth
auth.authenticate(credentials, self)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\auth.py", line 563, in authenticate
auth_func(credentials, sock_info)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\auth.py", line 540, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\auth.py", line 262, in _authenticate_scram
res = sock_info.command(source, cmd)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\pool.py", line 579, in command
unacknowledged=unacknowledged)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\network.py", line 150, in command
parse_write_concern_error=parse_write_concern_error)
File "C:\Users\adity\Desktop\crud-django\env\lib\site-packages\pymongo\helpers.py", line 155, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: Authentication failed.

最佳答案

在最新版本中使用客户端连接到数据库。我希望以下数据库配置能够解决您的问题。

DATABASES = {
'default': {
'ENGINE': 'djongo',
'ENFORCE_SCHEMA': True,
'LOGGING': {
'version': 1,
'loggers': {
'djongo': {
'level': 'DEBUG',
'propogate': False,
}
},
},
'NAME': 'my_db',
'CLIENT': {
'host': '127.0.0.1',
'port': 27017,
'username': 'XXXXXXXXXX',
'password': "XXXXXXXXXXXXX",
'authSource': 'admin',
'authMechanism': 'SCRAM-SHA-1'
}
}
}

关于django - pymongo.errors.OperationFailure : Authentication failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55520287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com