SSL handshake failed while connecting to cosmos DB for MongoDB using pymongo

Michael 31 Reputation points
2023-02-27T20:49:00.18+00:00

Hi,

I created an Azure Cosmos DB for MongoDB account in azure. I got SSL handshake failed error while connecting to it using pymongo.

This is how I connect:

from pymongo import MongoClient

client = MongoClient('mongodb://<account>:<password>@<account>.mongo.cosmos.azure.com:10255/?ssl=true&appName=@<account>@')

client.list_database_names()

I got error:


ServerSelectionTimeoutError: SSL handshake failed: <account>.mongo.cosmos.azure.com:10255: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 63fd123bc7b2500fd385cc68, topology_type: Single, servers: [<ServerDescription ('<account>.mongo.cosmos.azure.com', 10255) server_type: Unknown, rtt: None, error=NetworkTimeout('SSL handshake failed: <account>.mongo.cosmos.azure.com:10255: timed out')>]>

I have tried 3.2, 3.6, 4.0 and 4.2 version, but got same error for all of them. I'm using python 3.8 in WSL 2.0. (also tried python on windows but got same error too.) I have also verified my python is using TLS 1.2.

Can anyone please help?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,437 questions
{count} vote