Azure Cosmos DB emulator, fail to use it from python due to Firewall errors

2024-07-23T14:36:04.5533333+00:00

I've started a cosmos db in my docker on the windows machine, used Linux docker image.


docker run \
    --publish 8081:8081 \
    --publish 10250-10255:10250-10255 \
    --name linux-emulator \
    --detach \
    mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest    


I can access web portal through the https://localhost:8081/_explorer/index.html

However when I run my script, I get following error:

    raise exceptions.CosmosHttpResponseError(message=data, response=response)
azure.cosmos.exceptions.CosmosHttpResponseError: (Forbidden) Request originated from IP 167.16.252.82 through public internet. This is blocked by your Cosmos DB account firewall settings. More info: https://aka.ms/cosmosdb-tsg-forbidden

How do I configure firewall setting for the local emaulator running locally.

Here is a simple script i'm trying to run

from azure.cosmos import CosmosClient, PartitionKey


print('Connecting to Cosmos DB...')
client = CosmosClient(
    url="https://127.0.0.1:8081/",
    credential=(
        "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
    ),
)


print('creating database')
database = client.create_database_if_not_exists(
    id="cosmicworks",
    offer_throughput=400,
)
print('creating container')
container = database.create_container_if_not_exists(
    id="products",
    partition_key=PartitionKey(
        path="/id",
    ),
)

print('setting item')
item = {"id": "68719518371", "name": "Kiama classic surfboard"}

container.upsert_item(item)

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,664 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 21,725 Reputation points
    2024-07-23T15:39:40.2233333+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    I had same issue and solved with changing url="https://127.0.0.1:8081/" to url="https://localhost:8081/" by chance!

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is 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.