Search code examples
pythonazureazure-sdk-python

Using azure-sdk-for-python and MetricsQueryClient(credential).query_resource method produces a warning: 'InsecureRequestWarning: Unverified HTTPS requ


I have a python script where I want to check transaction number for my storage account, I am using:

`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]
)`

When I run it I'm getting a warning:

/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'management.azure.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings warnings.warn(

I have run it locally (VS Code, Windows) and on Github Actions (using OIDC), and keep getting the same warning (with different path at the beginning), but only when I run with |& tee -a output.txt to collect both stdout and stderr.

I am quite new to Azure and APIs in general, how can I make the connection safer?


Solution

  • try updating azure-monitor-query to the latest version 1.2.1. You may be pinning to an older version somewhere. You should try and make sure that azure-monitor-query>=1.2.1.

    pip install --upgrade azure-monitor-query