Hello,
I am attempting to connect to the Azure CosmosDB using MongoDB API in python and am receiving a ServerSelectionTimeoutError. I am using the read-write key provided in the quickstart connection guide. The default timeout time is 30 seconds. Below is a test for connection with modification for a 1ms timeout error that also fails. I experimented with 0ms and even longer than 30 seconds with no success.
`try:
client = pymongo.MongoClient(uri, serverSelectionTimeoutMS=1)
client.server_info()
except pymongo.errors.ServerSelectionTimeoutError as err:
print(err)`
here is the error from the above code.
No replica set members found yet, Timeout: 0.001s, Topology Description: <TopologyDescription id: 6039226389effc87c5d93363, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('<server>.mongo.cosmos.azure.com', port) server_type: Unknown, rtt: None>]>
I even tried connecting using my local mongo shell but that isn't working either. I received a similar error with exit code 1. But checking the mongodb docs, there isn't an error code 1
C:\Program Files\MongoDB\Server\4.4\bin> mongo.exe <server>:port -u <uname> -p <password> == --tls --tlsAllowInvalidCertificates MongoDB shell version v4.4.3 connecting to: mongodb://<server>.mongo.cosmos.azure.com:port/test?compressors=disabled&gssapiServiceName=mongodb Error: couldn't connect to <server>.mongo.cosmos.azure.com, connection attempt failed: NetworkTimeout: Error connecting to <server>.mongo.cosmos.azure.com:port (IP) :: caused by :: Socket operation timed out : connect@src/mongo/shell/mongo.js:374:17 @(connect):2:6 exception: connect failed exiting with code 1
Do I need to configure the PyMongo API with some specific TLS settings? I checked the documentation and it suggests I might need to add a path to a *.pem file, however I didn't find any such suggestion in Azure ComosDB documentation (tutorials, how-to-guides, or quickstart).
Code and errors are modified for privacy.