Calling cosmos db emulator remotely using python

Anonymous
2021-12-03T11:44:13.133+00:00

Hello,

By running the emulator using the following commands:

"C:\Program Files\Azure Cosmos DB Emulator\Microsoft.Azure.Cosmos.Emulator.exe" /GenKeyFile=cosmosdbauthkey
"C:\Program Files\Azure Cosmos DB Emulator\Microsoft.Azure.Cosmos.Emulator.exe" /AllowNetworkAccess /KeyFile=cosmosdbauthkey

I could access the emulator from another computer on the local area network by accessing
https://192.168.0.104/_explorer/index.html, as 192.168.0.104 is the IP address of the computer which we have installed cosmos db emulator.

I just wonder can we connect and create a cosmos client from a python program in other computer on the local area network?

On the computer where I have installed cosmos db emulator, I am using the following python code, and the cosmos client is successfully created:

from azure.cosmos import exceptions, CosmosClient, PartitionKey
endpoint = "https://localhost:8081"
key = 'C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=='
client = CosmosClient(endpoint, key)

However, I tried and use the following python code on another computer on the Local Area Network:

from azure.cosmos import exceptions, CosmosClient, PartitionKey
endpoint = "https://192.168.0.104:8081"
key = 'C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=='
client = CosmosClient(endpoint, key)

I got the following error:
ServiceRequestError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)

Is there any solution to solve this? Or cosmos db emulator just allow local development on the same machine?

brgds,
Millie

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

2 answers

Sort by: Most helpful
  1. Oury Ba-MSFT 20,911 Reputation points Microsoft Employee Moderator
    2021-12-03T22:27:34.63+00:00

    Hi @Anonymous Thank you for posting your Question on Microsoft Q&A.

    Sorry to hear that you are facing an issue when creating a cosmos client from a python code in a local area network.

    Python is the language on which the application is written, has nothing to do with the Emulator. The Emulator emulates the Cosmos DB backend. You can write your application in Python, C#, Java, NodeJS, that is the language of your application.

    if you have multiple machines using a single network, and if you set up the emulator on one machine and want to access it from another machine. In such case, you need to enable access to the emulator on a local network.

    You can run the emulator on a local network. To enable network access, specify the /AllowNetworkAccess option at the command-line, which also requires that you specify /Key=key_string or /KeyFile=file_name. You can use /GenKeyFile=file_name to generate a file with a random key upfront. Then you can pass that to /KeyFile=file_name or /Key=contents_of_file.

    To enable network access for the first time, the user should shut down the emulator and delete the emulator's data directory %LOCALAPPDATA%\CosmosDBEmulator.

    Let us know if you are still having issues.

    Regards,
    Oury


  2. Oury Ba-MSFT 20,911 Reputation points Microsoft Employee Moderator
    2021-12-06T17:53:31.393+00:00

    Hi @Anonymous

    Please follow the steps outlined in the article below for python apps.

    Export the Azure Cosmos DB Emulator certificates for use with Java, python, and Node.js App

    Regards,
    Oury


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.