pymongo.errors.OperationFailure: Authentication failed., full error


通过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"

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM