Server selection time out error

Hi,
I Started learning MongoDB atlas recently,and was trying to connect it with Jupyter notebook. im facing Server selection timeout error, and I’m unable to resolve it.
help me get rid of this.

ServerSelectionTimeoutError: cluster0-shard-00-02.gl4co.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125),cluster0-shard-00-00.gl4co.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125),cluster0-shard-00-01.gl4co.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125), Timeout: 30s, Topology Description: <TopologyDescription id: 621f7d6cb87ad4090bfca8ca, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.gl4co.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-00.gl4co.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125)')>, <ServerDescription ('cluster0-shard-00-01.gl4co.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-01.gl4co.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125)')>, <ServerDescription ('cluster0-shard-00-02.gl4co.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('cluster0-shard-00-02.gl4co.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125)')>]>

Hi @Narsimha_kalyan and welcome in the MongoDB Community :muscle: !

Could you please share the relevant lines from your Jupyter notebook so we have a chance to understand what is going wrong here. I’m guessing that you are in Atlas based on the URL I see.
Did you add your IP address in the IP access list correctly? Did you retrieve the connection string from the connection button in the UI?

Cheers,
Maxime.


Thanks for the reply. I’m attaching the relevant picture.Here I’m trying to create a collection.

The answer is written at the top of your image :wink: ! First line!

You need to install dnspython as you are using a DNS seed list to connect (mongodb+srv).

Cheers,
Maxime

Hi,
I tried installing dns python pip,and tried whitelisting my ip too. still im facing the issue.

You don’t need to import it. Just install it. It’s a dependency that pymongo will use in the background to resolve the URI and find the hosts based on the URL you provide.

2 Likes

No,Im still unable to resolve it @MaBeuLux88 .Any more alternatives?

I just started a new Jupyter notebook in a new folder with the command: jupyter notebook.
I created a new Python 3 notebook (ipykernel) using the web UI and gave it a name.

In the notebook I typed this: (I redacted my username and password)

Code:

from pymongo import MongoClient
client = MongoClient('mongodb+srv://USERNAME:PASSWORD@free.ne23r.mongodb.net/test?retryWrites=true&w=majority')
db = client.get_database('test')
coll = db.get_collection('coll')
coll.insert_one({'name': 'Maxime'})
print(coll.find_one())

And I ran the code and it was working out of the box. After some investigation, it’s actually working because I already have pymongo installed in the background with the dnspython lib. You can install them both with the command:

pip3 install pymongo[srv]

After this, I had to restart my jupyter notebook and rerun the code to make it work. Note that I’m using pip3 because I’m on Linux. Maybe it’s just pip on your system.

Cheers,
Maxime.