azure.core.exceptions.ServiceResponseError while uploading/retriving the data from Cosmos

Shubhankar Khandai 60 Reputation points
2024-11-11T06:30:13.3+00:00

While I am trying to access the Azure Cosmos, throug my Microsoft 365 cloud PC using Python I am getting the following error while retrieving/uploading into the container.
**azure.core.exceptions.ServiceResponseError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
**
What can be the main source of the error as the code looks fine and even If I try to use the code provided in the documentation of pypi for libarary azure-cosmos, its still the same.

import json
from azure.cosmos import CosmosClient
from configurations.config import Cosmos
endpoint = Cosmos.URL
key = Cosmos.KEY
client = CosmosClient(endpoint,key)

database_name = Cosmos.DATABASE
container_name = Cosmos.CONTAINER

database = client.get_database_client(database=database_name)
container = database.get_container_client(container=container_name)

query = "Select * from c"
items = list(container.query_items(query=query,enable_cross_partition_query=True))

for item in items:
    print(json.dumps(item))


FYI I am using the latest version of cosmos DB: 4.7.0

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,710 questions
Azure Firewall Manager
Azure Firewall Manager
An Azure service that provides central network security policy and route management for globally distributed, software-defined perimeters.
97 questions
Windows 365 Business
{count} votes

Accepted answer
  1. ShaktiSingh-MSFT 16,086 Reputation points
    2024-11-11T12:42:11.0133333+00:00

    Hi Shubhankar Khandai •,

    Welcome to Microsoft Q&A forum.

    As I understand, you are getting azure.core.exceptions.ServiceResponseError while uploading/retrieving the data from Cosmos.

    This could be due to Network and Firewall settings. Check your access from Microsoft 365 to Azure Cosmos DB is allowed and not restricted.

    Check TLS version between Azure Cosmos DB and Client is same.

    Was the connection working fine before? Or this is the first time you have established connectivity?

    Ensure that your Cosmos DB instance is configured to allow access from specific IP ranges (especially if Microsoft 365 Cloud PC uses a specific IP range).

    Let us know what your observation on above pointers was.

    Awaiting your reply.

    Thanks

    1 person found this answer helpful.

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.