Could not reach any servers - python


I have an issue with connection to the mongodb using python code. Appreciate if got any solution to this error. Had tried alot of options but did not work.

Error below:
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: Could not reach any servers in [(‘demo-db-0’, 27017)]. Replica set is configured with internal hostnames or IPs?, Timeout: 30s, Topology Description: <TopologyDescription id: 63c4cb5a9c09397560936c60, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘demo-db-0’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘demo-db-0:27017: [Errno 11001] getaddrinfo failed’)>]>

The client is unable to resolve demo-db-0 to an ip address.

Some possible resolutions:

  • The hostname might need to be added to dns.
  • You might need to add a domain to the hostname.
  • The client host might not have dns correctly configured. This could be incorrect dns servers or search domains.

The “demo-db-0” is mongo database name.