python sdk getting Status code: 404 connecting to cosmosdb

Rishabh Toshniwal 20 Reputation points
2023-11-17T16:20:14.9366667+00:00

Hi all,

I am getting 404 status code when I am doing any of the operation using CosmosClient.

I have cosmos db (mongo) setup in my subscription. While debugging I could see the "get_database_client"

& "get_container_client" works (as shown in the below screenshot), but all other operations ending with "Status code: 404\nb'', <class 'NoneType'>: None"

Python Packages :

azure-core==1.26.4

azure-cosmos==4.3.1

Python Code:


HOST = config.settings['host']
MASTER_KEY = config.settings['master_key']
DATABASE_ID = config.settings['database_id']
CONTAINER_ID = config.settings['container_id']

def run_sample():
    proxy_config = ProxyConfiguration()
    proxy = "http://XXXXXXXX.com:8080"
    if os.name == 'nt' and proxy is not None:
      proxy_config.Host = proxy
    client = cosmos_client1.CosmosClient(HOST, credential=MASTER_KEY, proxy_config = proxy_config, consistency_level = 'Session')
    db = client.get_database_client(DATABASE_ID)
    print ("db link", db.database_link)
    container = db.get_container_client(CONTAINER_ID)
    try:
       
      for i in range(2, 5):
        container.upsert_item({
            'id': 'item{0}'.format(i),
            'username': 'rishabht_{0}'.format(i),
            'type': 'bitbucket',
            'token': 'XXXXX'
        }
    )
    except exceptions.CosmosResourceNotFoundError as e:
       x =e  
       print(str(e))


User's image

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

Accepted answer
  1. Sajeetharan 2,261 Reputation points Microsoft Employee
    2023-11-18T17:35:38.5833333+00:00

    Hi Rishabh,

    For opensource APIs such as Mongo API, Cassandra API and Gremlin, we recommend using the opensource drivers. only for the NOSQL API we have our built in SDKs.

    In your case, you can use any of the opensource drivers mentioned here. https://www.mongodb.com/docs/drivers/

    Yes if you are using Python, then you can follow the quick start here, https://github.com/Azure-Samples/azure-cosmos-db-mongodb-python-getting-started


0 additional answers

Sort by: Most helpful

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.