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:password@myhost.com/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?