I'm attempting to connect to my MongoDB Atlas cluster from a Python application but am encountering an SSL handshake failure error. I've verified my MongoDB Atlas URI is correct and have tried several solutions without success.
Error Message:
Error connecting to MongoDB: SSL handshake failed: ac-efw9wvu-shard-00-02.ubua0y2.mongodb.net:27017: [('SSL routines', '', 'tlsv1 alert internal error')] (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),SSL handshake failed: ac-efw9wvu-shard-00-00.ubua0y2.mongodb.net:27017: [('SSL routines', '', 'tlsv1 alert internal error')] (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),SSL handshake failed: ac-efw9wvu-shard-00-01.ubua0y2.mongodb.net:27017: [('SSL routines', '', 'tlsv1 alert internal error')] (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 65e4
Details:
I'm using the pymongo library to connect to MongoDB Atlas with the following Python code snippet:
from pymongo import MongoClient, server_api
import certifi
# MongoDB Atlas connection URI
uri = 'mongodb+srv://<username>:<password>@<cluster-address>/?retryWrites=true&w=majority&appName=TaipeiYouBikeHourlyData'
# Use the certifi library to get the path of the CA certificate
ca = certifi.where()
try:
# Create a MongoClient instance and specify the CA certificate path
client = MongoClient(uri, server_api=server_api.ServerApi('1'), tlsCAFile=ca)
# Send a ping command to test the connection
response = client.admin.command('ping')
print("Successfully connected to MongoDB, response:", response)
except Exception as e:
print("Error connecting to MongoDB:", e)
Question:
Has anyone encountered similar SSL handshake failures with MongoDB Atlas, and how were you able to resolve it? Any suggestions on troubleshooting steps or configurations I might be missing?