I had my comsosdb instance with a private endpoint and Now I deleted it and switched to an open to all network configuration.
This is my simple python client:
import pymongo
uri = "XXXmyuriXXX"
myclient = pymongo.MongoClient(uri)
mydb = myclient["db"]
mycol = mydb["faculty"]
mydict = { "name": "John", "address": "Highway 37" }
x = mycol.insert_one(mydict)
The XXXmyuriXXX is the one provided in Python quickstart.
As described by the title I updated the firewall to allow access from all network to access to the cosmos db (testing phase) but still I am getting anhautorized error.
pymongo.errors.OperationFailure: Error=13, Details='Request originated
from IP 62.216.203.210 through public internet. This is blocked by
your Cosmos DB account firewall settings. More info:
https://aka.ms/cosmosdb-tsg-forbidden ActivityId:
6645e180-f1bc-424c-9628-c7391264e282, documentdb-dotnet-sdk/2.14.0
Host/64-bit MicrosoftWindowsNT/10.0.19041.0, full error: {'ok': 0.0,
'errmsg': "Error=13, Details='Request originated from IP
XXX.XXX.XXX.XXX through public internet.
This is blocked by your Cosmos DB account firewall settings. More info:
https://aka.ms/cosmosdb-tsg-forbidden\r\nActivityId:
6645e180-f1bc-424c-9628-c7391264e282, documentdb-dotnet-sdk/2.14.0
Host/64-bit MicrosoftWindowsNT/10.0.19041.0",
'code': 13, 'codeName':{'Unauthorized'}
The error says something about the firewall rules but there should not be any since I selected the allo-from-all-networks option. Any guess on how to access the cosmodb?
CodePudding user response:
By default Azure Cosmos DB is accessible without any restrictions over the internet. see :
Have you tried running the Quickstart for connecting a python app to MongoDB API ?
And make the connection like below :
client = pymongo.MongoClient(CONNECTION_STRING)
try:
client.server_info() # validate connection string
except pymongo.errors.ServerSelectionTimeoutError:
raise TimeoutError("Invalid API for MongoDB connection string or timed out when attempting to connect")
CodePudding user response:
I think the problem was related with the private endpoint connection I used to have. It is not the best solution but now I have created a cosmosdb from scratch and everything is working (I was lucky I did not have any production data inside difficult to replicate) . If anybody knows some azure client command to run in those cases it would be helpful. Thanks in advance