问题处理此类错误的最佳方法是什么?比如说,最多30秒后重试。 5次?
设置我在AWS ECS上有一个PRIMARY +两个SECONDARY设置,并且没有任何框已关闭。
从异常消息来看,似乎Mongo说“我没有PRIMARY,我试图从SECONDARY获取数据,但它们也已经失效”。但是,没有一个Mongo服务器出现故障。我有另一个进程运行,其中有一个read_preference
的默认SECONDARY
,并且运行正常。
例外
is_auth = db.authenticate("myid","mypass")
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
720, in authenticate
read_preference=read_pref)["nonce"]
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
390, in command
result = self["$cmd"].find_one(command, **extra_opts)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py",
line 598, in find_one
for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
814, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
763, in _refresh
self.__uuid_subtype))
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
700, in __send_message
**kwargs)
File
"/usr/local/lib/python2.7/dist-packages/pymongo/mongo_replica_set_client.py
", line 1210, in _send_message_with_response
raise AutoReconnect(msg, errors)
AutoReconnect: No replica set members available for query with
ReadPreference PRIMARY_PREFERRED
码
connection = MongoReplicaSetClient(, replicaSet='myReplica-2', use_greenlets = True)
db = "my_real_db"
db.read_preference = ReadPreference.PRIMARY
is_auth = db.authenticate("myid", "mypass") # ERROR at this line
版本MongoDB:2.2.0和PyMongo:2.4.2
检查你的connectTimeoutMS
和socketTimeoutMS
。可能是,它很小?
我会仔细检查您的副本集配置。在其中一个副本集成员上运行rs.status()
,并确保每个成员的“name”字段实际上是正确的,并从运行应用程序的计算机中解析。
我也遇到过这个问题。
rs.status()
and注意“syncingTo”字段的机器名称。/etc/hosts
。关于配置qazxsw poi的Mongodb文档找到了qazxsw poi。