pymongo.errors.OperationFailure: Authentication failed., full error
Posted on 2022-02-24 18:17 高&玉 阅读(2848) 评论(0) 编辑 收藏 举报通过python3连接MongoDB报错如下:
File "/usr/local/lib64/python3.6/site-packages/pymongo-4.0.1-py3.6-linux-x86_64.egg/pymongo/network.py", line 160, in command
parse_write_concern_error=parse_write_concern_error)
File "/usr/local/lib64/python3.6/site-packages/pymongo-4.0.1-py3.6-linux-x86_64.egg/pymongo/helpers.py", line 170, 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', '$clusterTime': {'clusterTime': Timestamp(1645694166, 1), 'signature': {'hash': b'\xe4\xe7L61\n\xba\xcf\xb3\xa4\xf9\xf9\x15\xcb\x93\xd0\x1f\xc7\xabV', 'keyId': 7054374532596891652}}, 'operationTime': Timestamp(1645694166, 1)}
python的连接URI:
uri = "mongodb://gaoyu:Password110@10.150.57.13:37071,10.150.57.13:37072,10.150.57.13:37073"
查看用户gaoyu,只有数据库gaoyu的权限
replicas:PRIMARY> show users
{
"_id" : "gaoyu.gaoyu",
"userId" : UUID("aa47e33f-ebac-48f3-96ee-23dea96373a1"),
"user" : "gaoyu",
"db" : "gaoyu",
"roles" : [
{
"role" : "readWrite",
"db" : "gaoyu"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
指定数据库即可
uri = "mongodb://gaoyu:Gaoyu029@10.150.57.13:37071,10.150.57.13:37072,10.150.57.13:37073/gaoyu"
« 上一篇: Reconfig attempted to install a config that would change the implicit default write concern. Use the setDefaultRWConcern command to set a cluster-wide write concern and try the reconfig again.
» 下一篇: Last reported error: Could not find host matching read preference { mode: "primary" } for set rs_shardsvr2
» 下一篇: Last reported error: Could not find host matching read preference { mode: "primary" } for set rs_shardsvr2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示