1
嘗試從python腳本啓動mongodb副本集,並運行到驗證錯誤。嘗試啓動pymongo中的副本集時出現身份驗證錯誤
from pymongo import MongoClient
ip = 'zzz.zz.zzz.zz'
port = 27017
replica_set = 'yomama'
config = {
'_id': replica_set,
'members': [
{'host': 'xxx.xx.xxx.xx',
'_id': 0,
'arbiterOnly': False},
{'host': 'yyy.yy.yyy.yy',
'_id': 1,
'arbiterOnly': False},
{'host': 'zzz.zz.zzz.zz',
'_id': 2,
'arbiterOnly': False},
],
}
connection = MongoClient(ip, port)
connection.admin.command('replSetInitiate', config)
運行此腳本導致:
pymongo.errors.OperationFailure: command SON([('replSetInitiate', {'_id': 'yomama', 'members': [{'host': 'xxx.xx.xxx.xx', '_id': 0, 'arbiterOnly': False}, {'host': 'yyy.yy.yyy.yy', '_id': 1, 'arbiterOnly': False}, {'host': 'zzz.zz.zzz.zz', '_id': 2, 'arbiterOnly': False}]})])
failed: unauthorized
沒有認證建立數據庫,並運行從蒙戈外殼一樣的東西工作正常:
db.runCommand({replSetInitiate:{'_id': 'yomama', 'members': [{'host': 'xxx.xx.xxx.xx', '_id': 0, 'arbiterOnly': false}, {'host': 'yyy.yy.yyy.yy', '_id': 1, 'arbiterOnly': false}, {'host': 'zzz.zz.zzz.zz', '_id': 2, 'arbiterOnly': false}]}})
{
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}
任何想法爲什麼這個錯誤時,與pymongo做同樣的事情?
我很困惑,你的迴應讓我覺得你確實設置了認證?我實際上正在嘗試做類似的事情,所以我只是想知道你是否做過認證設置 – rhealitycheck