The sample that you're following is applicable to only NOSQL (Core) API of Azure Cosmos DB.
To use Cosmos DB Mongo API with Python you can use any of the opensource drivers for python.
Follow this sample here.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello, I'm following all the code examples for the azure-cosmos python sdk to connect to my cosmos for mongodb and I get errors. I have Public network access for all networks and I'm using azure-cosmos from pip as said in the samples for python documentation: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/samples-python
I got the uri and port from settings > connections strings and the key from the primary password (read-write)
I'm out of ideas, would appreciate help here.
HOST = "https://my-cosmos.mongo.cosmos.azure.com:10255/"
MASTER_KEY = "my_primary_key=="
client = cosmos_client.CosmosClient(HOST, credential=MASTER_KEY )
>> Exception has occurred: ServiceResponseError ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
connection_string = "AccountEndpoint=https://my-cosmos.mongo.cosmos.azure.com:10255/;AccountKey=my_key"
client = cosmos_client.CosmosClient.from_connection_string(connection_string)
>> Exception has occurred: ServiceResponseError ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
The sample that you're following is applicable to only NOSQL (Core) API of Azure Cosmos DB.
To use Cosmos DB Mongo API with Python you can use any of the opensource drivers for python.
Follow this sample here.
Thank you for reaching out.
My understanding is that you are facing an issue while connecting your Azure cosmos db Mongo db Python SDK.
The sample you linked is only for Azure Cosmos DB for NoSQL accounts and isn’t compatible with the API for MongoDB. All of the SDKs developed and owned by our team are only for the NoSQL API, and you can use the native SDKs themselves to connect to the OSS APIs (MongoDB, Cassandra etc).
There’s a tutorial on how to connect to an Azure Cosmos DB for MongoDB account using python here: Get started with Azure Cosmos DB for MongoDB and Python | Microsoft Learn
Regards,
Oury