Cannot connect to Atlas cluster on MacOS

Hi,
I’m having an issue connecting to my Atlas cluster in a Jupyter notebook. When I run a query, I receive the following traceback:

ServerSelectionTimeoutError: cluster0-shard-00-02.wapdt.mongodb.net:27017: [SSL: 
CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
(_ssl.c:1045),cluster0-shard-00-01.wapdt.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] 
certificate verify failed: unable to get local issuer certificate (_ssl.c:1045),cluster0-shard-00- 
00.wapdt.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to 
get local issuer certificate (_ssl.c:1045), Timeout: 30s, Topology Description: <TopologyDescription id: 
6090ddc81b3959247ae64e09, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription 
('cluster0-shard-00-00.wapdt.mongodb.net', 27017) server_type: Unknown, rtt: None, 
error=AutoReconnect('cluster0-shard-00-00.wapdt.mongodb.net:27017: [SSL: 
CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
(_ssl.c:1045)')>, <ServerDescription ('cluster0-shard-00-01.wapdt.mongodb.net', 27017) server_type: 
Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-01.wapdt.mongodb.net:27017: [SSL: 
CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
(_ssl.c:1045)')>, <ServerDescription ('cluster0-shard-00-02.wapdt.mongodb.net', 27017) server_type: 
Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-02.wapdt.mongodb.net:27017: [SSL: 
CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate 
(_ssl.c:1045)')>]>

This is what my MongoClient initialization looks like:

uri = 'mongodb+srv://xxx:yyy@cluster0.wapdt.mongodb.net/shopalot? 
retryWrites=true&w=majority'
client = MongoClient(uri, tls=True, tlsCAFile=certifi.where())

I’ve tried all possible steps at TLS/SSL and PyMongo — PyMongo 4.3.3 documentation (including running the “Install Certificates.command”) and ensured that my IP address is whitelisted in Atlas. I also tried setting tlsAllowInvalidCertificates to True and I somehow still get the same error.

I am able to connect to my cluster through MongoDB Compass but I still do need to find a way to be able to run my Jupyter notebook.

What am I missing here?

Thank you for any help you can offer!

Did you try connecting without specifying a certificate?

ssl=True,ssl_cert_reqs='CERT_NONE'

or any options, like Atlas example shows:

client = pymongo.MongoClient("mongodb+srv://<username>:<password>@xxx.yyyy.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
1 Like

Interestingly, when I ran my queries today/just now, everything began to work. I’m able to connect with the options I mentioned in the post, without specifying a certificate, and without any options. Not sure what changed overnight, but thank you so much for taking the time to provide some options for me!

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.