Skip to content

Azure-mgmt-monitor credential can't get token #14044

@dommgifer

Description

@dommgifer
  • Package Name:
    azure-mgmt-monitor

  • Package Version:
    1.0.1

  • Operating System:
    Ubuntu 18.04

  • Python Version:
    3.7

Describe the bug
I want to get VM CPU usage,
So I run MonitorClient(credentials, subscription_id).metrics.list()

But get error message:

AttributeError
'coroutine' object has no attribute 'token'

To Reproduce
Steps to reproduce the behavior:

  1. Install package
    azure-identity==1.4.0
    azure-core==1.8.1
    azure-mgmt-monitor==1.0.1

  2. My credentials from ServicePrincipalCredentials

from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
           tenant = tenant_id,
           client_id= app_id,
           secret = password
        )
  1. Get monitor_client
from azure.mgmt.monitor import MonitorClient
monitor_client = MonitorClient(credentials, subscription_id)
  1. Call metrics.list()
metrics_data = monitor_client.metrics.list(
            resource_id,
            timespan="{}/{}".format('2020-09-25T00:00:00', '2020-09-25T02:00:00'),
            interval='PT1M',
            metricnames='Percentage CPU',
            aggregation='Average'
        )
  1. Get Error
AttributeError
'ServicePrincipalCredentials' object has no attribute 'get_token'
  1. Change credentials from ClientSecretCredential
    Reference by azure-mgmt-monitor/tests/test_cli_mgmt_monitor.py
from azure.identity.aio import ClientSecretCredential
credentials = ClientSecretCredential(
            tenant = tenant_id,
           client_id= app_id,
           secret = password
        )
  1. Run same code in step 2 and 3 again, Get error
AttributeError
'coroutine' object has no attribute 'token'

Expected behavior
Get VM CPU usage

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
All my code:

from azure.mgmt.monitor import MonitorClient
from azure.identity.aio import ClientSecretCredential
credentials = ClientSecretCredential(
            tenant = tenant_id,
           client_id= app_id,
           secret = password
        )

monitor_client = MonitorClient(credentials, subscription_id)
metrics_data = monitor_client.metrics.list(
            resource_id,
            timespan="{}/{}".format('2020-09-25T00:00:00', '2020-09-25T02:00:00'),
            interval='PT1M',
            metricnames='Percentage CPU',
            aggregation='Average'
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions