Git Product home page Git Product logo

cosmos-db-nosql-python-samples's Introduction

Azure Cosmos DB for NoSQL client library samples for Python

Validate Python projects

Getting started

This repo has a devcontainer environment making it easy to get started.

Open in GitHub Codespaces

Run the app

Configure your Azure Cosmos DB credentials as environment variables.

export COSMOS_ENDPOINT="<cosmos-account-URI>"
export COSMOS_KEY="<cosmos-account-PRIMARY-KEY>"

๐Ÿ’ก TIP: If you don't have an Azure Cosmos DB account, create a free account.

Run the quickstart sample app using the azure-cosmos package from PyPI.

pip install azure-cosmos
python 001-quickstart/app.py

Validate any changes you make

If you change the code, run the linter and code formatter.

pip install flake8
flake8 --verbose 001-quickstart/app.py
pip install black
black --verbose 001-quickstart/app.py

Troubleshooting

If you use a self-signed certificate to connect your Cosmos DB instance (Cosmos-emulator, Docker image, proxy, ...), you can define your own certificate in the REQUESTS_CA_BUNDLE environment variable :

export REQUESTS_CA_BUNDLE='/etc/ssl/certs/emulatorcert.pem'

cosmos-db-nosql-python-samples's People

Contributors

anandmeg avatar microsoftopensource avatar rom1detroyes avatar seesharprun avatar vmagelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cosmos-db-nosql-python-samples's Issues

Can't use self signed certificate (using Docker container for Cosmos DB) with 001-quickstart samples

Hello,

I try to run the samples here with a Docker image of Cosmos DB, taken from :
https://learn.microsoft.com/en-us/azure/cosmos-db/docker-emulator-linux?tabs=sql-api%2Cssl-netstd21

Following the README, I get this error :

python 001-quickstart/app.py
Traceback (most recent call last):
  File "/home/romain/Projects/cosmos-db-nosql-python-samples/001-quickstart/app.py", line 27, in <module>
    database = client.create_database_if_not_exists(id=DATABASE_NAME)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/cosmos_client.py", line 319, in create_database_if_not_exists
    database_proxy.read(
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/database.py", line 141, in read
    self._properties = self.client_connection.ReadDatabase(
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_cosmos_client_connection.py", line 342, in ReadDatabase
    return self.Read(path, "dbs", database_id, None, options, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2201, in Read
    result, self.last_response_headers = self.__Get(path, request_params, headers, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2249, in __Get
    return synchronized_request.SynchronizedRequest(
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_synchronized_request.py", line 206, in SynchronizedRequest
    return _retry_utility.Execute(
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_retry_utility.py", line 83, in Execute
    result = ExecuteFunction(function, global_endpoint_manager, *args, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_retry_utility.py", line 144, in ExecuteFunction
    return function(*args, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_synchronized_request.py", line 131, in _Request
    response = _PipelineRunFunction(
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_synchronized_request.py", line 172, in _PipelineRunFunction
    return pipeline_client._pipeline.run(request, **kwargs)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 205, in run
    return first_node.send(pipeline_request)  # type: ignore
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 69, in send
    response = self.next.send(request)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 69, in send
    response = self.next.send(request)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 69, in send
    response = self.next.send(request)
  [Previous line repeated 1 more time]
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_retry_utility.py", line 215, in send
    raise err
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/cosmos/_retry_utility.py", line 192, in send
    response = self.next.send(request)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 69, in send
    response = self.next.send(request)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 69, in send
    response = self.next.send(request)
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 69, in send
    response = self.next.send(request)
  [Previous line repeated 1 more time]
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 100, in send
    self._sender.send(request.http_request, **request.context.options),
  File "/home/romain/.asdf/installs/python/3.10.10/lib/python3.10/site-packages/azure/core/pipeline/transport/_requests_basic.py", line 376, in send
    raise error
azure.core.exceptions.ServiceRequestError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)

My Cosmos DB is running fine, I can access the web console and had exported the end point and key in my env :

Is there a way to get rid of this ?

Maybe this exception could be catched with a user friendly-er message ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.