Reputation: 11042
I am trying to connect to a remote mongodb server using pymongo
, but I am getting error. The connection works in Studio3T
. I am behind VPN, but I am sure the issue is not related with it otherwise the connection via Studio3T
wouldn't work either. The error I am getting is
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')>]>
This is the code I am using
from pymongo import MongoClient
client = MongoClient("mongodb://remote_server_ip:27017/")
client.server_info()
Upvotes: 5
Views: 3684
Reputation: 370
For those who're using pymongo 4 version, need to explicitly set directConnection
as True
in MongoClient options.
More information here https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#directconnection-defaults-to-false
Upvotes: 1
Reputation: 11042
Turns out this was pymongo version issue.. Version 3.12 worked for me
python3 -m pip install pymongo==3.12
Upvotes: 2