首页 > 解决方案 > OperationFailure:尽管凭据正确,但在插入 MongoDB 集合时身份验证失败

问题描述

我有一个 MongoDB 数据库,我尝试从一个协作笔记本中添加一些东西:

client = pymongo.MongoClient("mongodb+srv://test:<mypassjeje>@<unique identifier>.mongodb.net/<dbnamejojo>?retryWrites=true&w=majority")
db = client.test
fragrance = db.fragrance_db

我用测试用户的密码和默认情况下连接将使用的数据库的名称替换。

Pero cuando intento insertar una cosa:

fragrance.insert_one(perfume)

它返回:

---------------------------------------------------------------------------
OperationFailure                          Traceback (most recent call last)
<ipython-input-48-d831294ab74e> in <module>()
     46         count += 1
     47 
---> 48 __main__()

19 frames
/usr/local/lib/python3.6/dist-packages/pymongo/helpers.py in _check_command_response(response, max_wire_version, msg, allowable_errors, parse_write_concern_error)
    166             msg = msg or "%s"
    167             raise OperationFailure(msg % errmsg, code, response,
--> 168                                    max_wire_version)
    169 
    170 

OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}

我也在最后尝试&authSource=admin

client = pymongo.MongoClient("mongodb+srv://test:<mypassjeje>@<unique identifier>.mongodb.net/<dbnamejojo>?retryWrites=true&w=majority&authSource=admin")

但它返回相同的错误:

OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}

标签: pythonpython-3.xmongodb

解决方案


推荐阅读