SSL issue when using Cosmos DB Emulator (Linux version)

Ruiqi Liu 5 Reputation points
2023-10-17T18:13:27.3533333+00:00

Hi, I was trying to make Cosmos DB Emulator work with python client. But ran into SSL issues. I mostly followed the doc here and here.

Can you suggest how to fix it? I am open to disable SSL if that's doable. Here are the steps on my Linux localhost:

  1. docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
  2. EMULATOR_KEY="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
docker run \
>     --publish 8081:8081 \
>     --publish 10250-10255:10250-10255 \
>     --memory 3g --cpus=4.0 \
>     --name=cosmosdb \
>     --env AZURE_COSMOS_EMULATOR_PARTITION_COUNT=5 \
>     --env AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false \
>     --env AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr \
>    --env AZURE_COSMOS_EMULATOR_KEY=$EMULATOR_KEY \
>   --env ADDITIONAL_JVM_ARGS="-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts"\
>     --interactive \
>     --tty \
>     mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
curl -k https://127.0.0.1:8081/_explorer/emulator.pem > ~/emulatorcert.crt
sudo cp ~/emulatorcert.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates

5 pip install azure-cosmos

6 have a file of app.py

from azure.cosmos import CosmosClient, PartitionKey   client = CosmosClient(     url="https://localhost:8081",     credential=(         "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="     ), )  database = client.create_database_if_not_exists(     id="cosmicworks",     offer_throughput=400, )  container = database.create_container_if_not_exists(     id="products",     partition_key=PartitionKey(         path="/id",     ), )  item = {"id": "68719518371", "name": "Kiama classic surfboard"}  container.upsert_item(item)

client = CosmosClient(     url="https://localhost:8081",     credential=(         "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="     ), )

database = client.create_database_if_not_exists(     id="cosmicworks",     offer_throughput=400, )

container = database.create_container_if_not_exists(     id="products",     partition_key=PartitionKey(         path="/id",     ), )

7 python app.py

got below error

azure.core.exceptions.ServiceRequestError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,543 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Sajeetharan 2,031 Reputation points Microsoft Employee
    2023-10-24T12:56:04.3133333+00:00

    Hi @Ruiqi Liu , error does not have anything to do with the Cosmos DB emulator.

    You can try the solution mentioned here, https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/42334357#42334357