Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pymongo "[Errno -5] No address associated with hostname" fixed, but why?

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?

like image 794
John Gordon Avatar asked Jan 26 '26 00:01

John Gordon


1 Answers

  1. You changed the URI.

  2. All software has issues, maybe you found one.

like image 93
D. SM Avatar answered Jan 28 '26 15:01

D. SM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!