azure-sdk-for-python: AttributeError: 'UserPassCredentials' object has no attribute 'get_token'
import os
from msrestazure.azure_active_directory import UserPassCredentials
from azure.mgmt.resource import ResourceManagementClient
credentials = UserPassCredentials(username=os.getenv('AZURE_USERNAME'), password=os.getenv('AZURE_PASSWORD'))
subscription_id = os.getenv('AZURE_SUBSCRIPTION')
resource_client = ResourceManagementClient(credentials, subscription_id)
resource_list = resource_client.resource_groups.list()
for resource in resource_list:
print(resource)
For the above code I am running into the error -
AttributeError: ‘UserPassCredentials’ object has no attribute ‘get_token’
I have to use Active directory to authenticate. I have the token embedded inside the credentials. I think I am missing something here. Can you please guide me in the right direction on how can I list all the resource group in my subscriptions using the credentials that I generated or if I need to use a different method.
Update 1 - Fixed a typo
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (7 by maintainers)
Ah, I see, the issue then is azure-mgmt-subscription’s SubscriptionClient, which expects an msrestazure credential. I’m not so familiar with these libraries, but I see there’s a
azure.mgmt.resource.subscriptions.SubscriptionClient
that might be all you need to list subscriptions. If you must use azure-mgmt-subscription and want to use the same credential object with ResourceManagementClient and SubscriptionClient, you could use AzureIdentityCredentialWrapper. It wraps an msrestazure credential with the azure-identity API, allowing you to usemsrestazure.azure_active_directory.UserPassCredentials
with ResourceManagementClient.@changlong-liu what’s the story with azure-mgmt-subscription? Will it have a track 2 version?