Hi,
- I have managed to resolve my connection and also using the new connection string “mongodb+srv”:
Let me recap: I have pymongo version 4.0.1 and dnspython version 2.1.0 installed.
Following these two trouble-shooting posts:
https : // stackoverflow . com/questions/53576199/all-nameservers-failed-to-answer-udp-port-53-google-cloud-functions-python-3-7-a
https: // forum .omz-software . com/topic/6751/pymongo-errors-configurationerror-resolver-configuration-could-not-be-read-or-specified-no-nameservers/6
We need to do this first before the “import pymongo” statement, so that DNS can be resolved before looking up the cluster shard ( ? ).
import dns.resolver
dns.resolver.default_resolver=dns.resolver.Resolver(configure=False)
dns.resolver.default_resolver.nameservers=[‘8.8.8.8’] # this is a google public dns server, use whatever dns server you like here # as a test, dns.resolver.query(‘www.google.com’) should return an answer, not an exception
import pymongo