简体   繁体   English

如何使用 Python 使用代理 IP 连接到 Cosmos DB

[英]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.我正在尝试使用下面的代理主机和端口使用 python 连接到 Cosmos DB。 The Cosmos DB is configured to accept ip = 100.100.10.0/25 Cosmos DB 配置为接受 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. 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: Python 代码:

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.您的代码是正确的,但您需要将代理主机添加到 Cosmos DB 中的防火墙。

在此处输入图像描述

BTW, firewall changes may take up to 15 minutes.顺便说一句,防火墙更改最多可能需要 15 分钟。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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