SSL issue when using Cosmos DB Emulator (Linux version)

Ruiqi Liu 0 Reputation points
2023-10-17T18:15:51.1833333+00:00

Hi, I was trying to make Cosmos DB Emulator work with python client. But ran into SSL issues. I mostly follow the doc export certificate instructions and python example.

Can you suggest how to fix it? I am open to disable SSL if that's doable.

Here are the steps:

  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,474 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 19,235 Reputation points
    2023-10-18T03:44:45.46+00:00

    You can disable SSL verification in your Python code as:

    import requests 
    requests.packages.urllib3.disable_warnings()