Using this code with a somewhat older version of PyMongo (I believe it was 3.5 or 3.6):
from pymongo import MongoClient
client = MongoClient('mongodb://username:[email protected]/db_name?retryWrites=true&w=majority')
db = client['db_name']
collection = db['collection_name']
for document in collection.find():
# do stuff with document
I was getting this error on the collection.find() call:
pymongo.errors.ServerSelectionTimeoutError: myhost.com:27017: [Errno -5] No address associated with hostname
After upgrading to PyMongo 3.11 and using mongodb+srv:// in the db connect string, the error went away.
My question is: Why? "No address associated with hostname" seems like a DNS-level error. Why did a simple library upgrade fix it?
You changed the URI.
All software has issues, maybe you found one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With