我正在尝试使用 pymongo 连接到远程 mongodb 服务器,但出现错误。该连接在 Studio3T
中有效。我支持 VPN,但我确信问题与其无关,否则通过 Studio3T
的连接也将无法工作。我收到的错误是
pymongo.errors.ServerSelectionTimeoutError: mongo-arb:27017: [Errno -3] Temporary failure in name resolution,mongo-sec:27017: [Errno -3] Temporary failure in name resolution,mongo-sec2:27017: [Errno -3] Temporary failure in name resolution,mongo:27017: [Errno -3] Temporary failure in name resolution, Timeout: 30s, Topology Description: <TopologyDescription id: 62ea25815b38c5f0b06416d3, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('mongo', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongo:27017: [Errno -3] Temporary failure in name resolution')>, <ServerDescription ('mongo-arb', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongo-arb:27017: [Errno -3] Temporary failure in name resolution')>, <ServerDescription ('mongo-sec', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongo-sec:27017: [Errno -3] Temporary failure in name resolution')>, <ServerDescription ('mongo-sec2', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongo-sec2:27017: [Errno -3] Temporary failure in name resolution')>]>
这是我正在使用的代码
from pymongo import MongoClient
client = MongoClient("mongodb://remote_server_ip:27017/")
client.server_info()
最佳答案
原来这是 pymongo 版本问题..版本 3.12 对我有用
python3 -m pip install pymongo==3.12
关于python-3.x - 名称解析暂时失败,mongo-sec :27017,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73217987/