pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed

pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: my-clus1-shard-00-00-pri.xyz.mongodb.net:27017: [SSL: WRONG_VERSION_NUMBER]

Flask==2.0.2
Flask-PyMongo==2.2.0
requests==2.20.1
pymongo[tls,srv]==4.0.1

Any idea why the wrong ssl is from the packages or something else

What operating system, Python version and MongoDB version, and are you trying to connect through a proxy?

Docker
FROM python:3.6.8-alpine3.9

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt

RUN pip install gunicorn

COPY flaskr/bar.py .

EXPOSE 5000

CMD [“python”, “bar.py”]

What version of MongoDB and where is MongoDB running?

I found that the ssl issue is a red herring , i was trying to connect to a db in a different region and the error presented as such.

Its very strange and dishearting none the less everything is working now

how did you fixed it?, i have the same error

It may be due to the OpenSSL updates. If you are on ubuntu:22.04, upgrade to ubuntu:23.x. However what OS are you on right now and the mongodb version now?

Hi, check your network access configuration in Atlas in case you are connecting to it.

In my case, I was connecting to an instance in Atlas. As long as I have added the new IP, I was using from my network, I could connect

2 Likes

YES!!! I encountered the same error and after 2 hours of troubleshooting this is what solved my issue. Just add your IP to the cluster

1 Like

That error is usually due to a configuration issue in MongoDB Atlas. When you connect from your localhost, there’s no problem because MongoDB Atlas configures your IP address. However, when you move to production, whether it’s AWS, Azure, DigitalOcean, etc., you need to grant access to the public IP. That’s how I resolved it.

In plataform go to: SECURITY/NETWORK ACCESS
image

2 Likes

This worked. adding the ip address worked for me.

I’m also encountering the same error: SSL handshake failed.

I’m using MongoDB version 8.0.9, and I’ve verified that it is accessible from Network Access settings. Most of the time, the application works fine, but occasionally I get this SSL handshake error.
My application is running on the python:3.10-slim Docker image, which I believe is based on Debian Linux.
Can anyone suggest how to resolve this intermittent error?