Reputation: 765
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?
Upvotes: 0
Views: 2014
Reputation: 1394
By default Azure Cosmos DB is accessible without any restrictions over the internet.
see : https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-configure-vnet-service-endpoint
Have you tried running the Quickstart for connecting a python app to MongoDB API ? https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/create-mongodb-python
Also you uri needs to be the connection string. what value did you use for the uri here uri = "XXXmyuriXXX"
? did you use the connection string or just the endpoint?
You can find the connection string here :
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")
Upvotes: 1