pymongo连接mongodb鉴权失败
报错信息:
xmlrpclib.Fault: <Fault 1: "<class 'pymongo.errors.OperationFailure'>:command SON([('saslStart', 1), ('mechanism', 'SCRAM-SHA-1'), ('payload', Binary('n,,n=admin,r=NDkzNDIzMzI3OTY1', 0)), ('autoAuthorize', 1)]) on namespace malware_detection_cache.$cmd failed: Authentication failed.">
解决方法:
在Mongodb 4 中增加authSource信息,解决方法如下
client = MongoClient(host=<<hostname>>, port=<<port>>, username=<<user_name>>, password=<<password>>, authSource="admin") db_obj = client[db_name]