Been wrestling with this for a long time. This setup works fine on a Mac. Moving the same setup to Ubuntu causes some issue relating to PyMongo connecting to our Atlas cluster. Using the mongo shell directly on the same Ubuntu box works fine. But attempting to use the MongoClient fails every time with a No replica set members found yet.
We've tried going back to 3.4x related versions and it made no difference.
Again, we can connect via bash using the mongo shell 3.6.1 and it works perfectly.
However, we cannot get MongoClient (pymongo 3.4) to make the connection. We've also attempted to put in delays (concerned about forking or other conflicts), but it had no affect. We've tried connect=False (no difference).
>>> from pymongo import MongoClient
>>> atlas = "mongodb+srv://xxxx:firstname.lastname@example.org/test"
>>> client = MongoClient(atlas)
>>> db = client.test
>>> cursor = db.transactions.count()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/Environs/env/local/lib/python2.7/site-packages/pymongo/collection.py", line 1559, in count
return self._count(cmd, collation, session)
File "/home/ubuntu/Environs/env/local/lib/python2.7/site-packages/pymongo/collection.py", line 1503, in _count
with self._socket_for_reads() as (sock_info, slave_ok):
File "/usr/lib/python2.7/contextlib.py", line 17, in _enter_
File "/home/ubuntu/Environs/env/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 979, in _socket_for_reads
server = topology.select_server(read_preference)
File "/home/ubuntu/Environs/env/local/lib/python2.7/site-packages/pymongo/topology.py", line 224, in select_server
File "/home/ubuntu/Environs/env/local/lib/python2.7/site-packages/pymongo/topology.py", line 183, in select_servers
selector, server_timeout, address)
File "/home/ubuntu/Environs/env/local/lib/python2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
pymongo.errors.ServerSelectionTimeoutError: No replica set members found yet
MongoDB shell version v3.6.1
git version: 025d4f4fe61efd1fb6f0005be20cb45a004093d1
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
pip freeze | grep pymongo
python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
python -c "import sys; print(sys.version)"
2.7.6 (default, Oct 26 2016, 20:30:19)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
But this works on the same machine…
mongo "mongodb+srv://cluster0-xxxx.mongodb.net/test” --authenticationDatabase admin --username xxxx --password xxxx --ssl