question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'UserPassCredentials' object has no attribute 'get_token'

See original GitHub issue
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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
chlowellcommented, Nov 2, 2020

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 use msrestazure.azure_active_directory.UserPassCredentials with ResourceManagementClient.

@changlong-liu what’s the story with azure-mgmt-subscription? Will it have a track 2 version?

0reactions
msftbot[bot]commented, Jan 27, 2022

Hi, we’re sending this friendly reminder because we haven’t heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don’t hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

'ServicePrincipalCredentials' object has no attribute 'get_token'
Run pip install azure-identity to get the package. References: Azure SDK for Python on GitHub.
Read more >
Why am I getting AttributeError: Object has no attribute?
PYTHON : Why am I getting AttributeError : Object has no attribute ? [ Gift : Animated Search Engine ...
Read more >
AttributeError: 'Token' object has no attribute 'test' solved
This video will help to solve attribute error while rendering templates in flask...
Read more >
AttributeError: 'int' object has no attribute 'split' - YouTube
fixed attributeerror : 'int' object has no attribute 'split'thanks for watching! subscribe(); to support 00110110 thank you ...
Read more >
msrestazure.azure_active_directory.UserPassCredentials class
Credentials object for Headless Authentication, i.e. AAD authentication via username and password. Headless Auth requires an AAD login (no a Live ID) that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found