简体   繁体   中英

How to connect to Cosmos DB using Proxy IP using Python

I am trying to connect to Cosmos DB using python using below proxy host and port. The Cosmos DB is configured to accept ip = 100.100.10.0/25

But, it seems to not connect.

Exception says- azure.cosmos.exceptions.CosmosHttpResponseError: (Forbidden) Request originated from client IP 198.110.10.10 through public internet. This is blocked by your Cosmos DB account firewall settings. azure.cosmos.exceptions.CosmosHttpResponseError: (Forbidden) Request originated from client IP 198.110.10.10 through public internet. This is blocked by your Cosmos DB account firewall settings.

Python Code:

from azure.cosmos import CosmosClient, exceptions, ProxyConfiguration

url = 'XXXX'
key = 'XXXX'

d = ProxyConfiguration()
d.Host = '100.100.10.0'
d.Port = 25
client = CosmosClient(url, credential=key, proxy_config=d)

database_name = 'testDatabase'
try:
    database = client.create_database(database_name)
except exceptions.CosmosResourceExistsError:
    database = client.get_database_client(database_name)

Exception:

File "C:\Users\AppData\Roaming\Python\Python37\site-packages\azure\cosmos\_synchronized_request.py", line 158, in _Request
raise exceptions.CosmosHttpResponseError(message=data, response=response)
    azure.cosmos.exceptions.CosmosHttpResponseError: (Forbidden) Request originated from client IP 198.110.10.10 through public internet. This is blocked by your Cosmos DB account firewall settings.

Your code is correct, but your need add your Proxy Host to firewall in Cosmos DB.

在此处输入图像描述

BTW, firewall changes may take up to 15 minutes.

Ref: https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-configure-firewall

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM