使用azure-sdk-for-python和MetricsQueryClient(credential).query_resource方法时出现警告:'InsecureRequestWarning: 未验证的HTTPS请求

0 投票
1 回答
51 浏览
提问于 2025-04-13 20:30

我有一个Python脚本,想要检查我的存储账户的交易数量,我使用的是:

`cred = DefaultAzureCredential()    
client_metrics = MetricsQueryClient(cred)

#the response is provided as timeseries data with daily number of transactions for past 30 days
response = client_metrics.query_resource(
    resource_id,
    metric_names=["Transactions"],
    timespan=timedelta(days=30),
    granularity=timedelta(days=1),
    aggregations=[MetricAggregationType.TOTAL]
)`

当我运行这个脚本时,出现了一个警告:

/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/urllib3/connectionpool.py:1103: 不安全请求警告:正在向主机 'management.azure.com' 发出未经验证的HTTPS请求。强烈建议添加证书验证。详情请见:https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings warnings.warn(

我在本地(使用VS Code,Windows)和在Github Actions(使用OIDC)上运行这个脚本时,都会收到同样的警告(只是开头的路径不同),但只有在我使用|& tee -a output.txt来同时收集标准输出和错误输出时才会出现。

我对Azure和API还很陌生,怎么才能让连接更安全呢?

1 个回答

1

试着把 azure-monitor-query 更新到最新版本 1.2.1。你可能在某个地方固定了一个旧版本。你应该确保 azure-monitor-query>=1.2.1

pip install --upgrade azure-monitor-query

撰写回答