-
Notifications
You must be signed in to change notification settings - Fork 3k
AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token' on resource_groups.list() #16908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for opening this issue! That sample code is out of date (@jongio, are you still tracking old samples?). The latest azure-mgmt-resource (15.x) expects a credential from azure-identity, whose ClientSecretCredential is the equivalent of azure.common.credentials.ServicePrincipalCredentials. It takes the same information but its parameters are slightly different: import os
from azure.identity import ClientSecretCredential
from azure.mgmt.resource import ResourceManagementClient
credential = ClientSecretCredential(
tenant_id=os.environ["AZURE_TENANT_ID"],
client_id=os.environ["AZURE_CLIENT_ID"],
client_secret=os.environ["AZURE_CLIENT_SECRET"]
)
client = ResourceManagementClient(credential, os.environ["AZURE_SUBSCRIPTION_ID"])
print(client.resource_groups.list())
for item in client.resource_groups.list():
print(item) I showed creating ClientSecretCredential above to demonstrate the difference vs. ServicePrincipalCredentials. However, using EnvironmentCredential is simpler (it will read the same variables): from azure.identity import EnvironmentCredential
credential = EnvironmentCredential() (Related: #14919) |
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @darshanhs90, @AshishGargMicrosoft. Issue Details
Describe the bug To Reproduce #!/usr/bin/python
import os
import json
from datetime import datetime
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
### Gets Azure resource groups and virtual machines
# I assume the following variables exist
# AZURE_TENANT_ID: with your Azure Active Directory tenant id or domain
# AZURE_CLIENT_ID: with your Azure Active Directory Application Client ID
# AZURE_CLIENT_SECRET: with your Azure Active Directory Application Secret
# AZURE_SUBSCRIPTION_ID: with your Azure Subscription Id
def main():
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID")
client_id = os.environ.get("AZURE_CLIENT_ID")
client_secret = os.environ.get("AZURE_CLIENT_SECRET")
tenant_id = os.environ.get("AZURE_TENANT_ID")
credentials = ServicePrincipalCredentials(
client_id = client_id,
secret = client_secret,
tenant = tenant_id
)
print(credentials)
client = ResourceManagementClient(credentials, subscription_id)
print(client.resource_groups.list())
for item in client.resource_groups.list():
print(item)
main() This produces:
Expected behavior Additional context
|
I'm looking into this for an update. |
Close this as it's duplicated issue with #14919. |
Describe the bug
Attribute Error duing resource list
To Reproduce
Steps to reproduce the behavior:
main.py:
This produces:
Expected behavior
Should print the item without crashing.
Additional context
I am following the example in https://github.com/Azure-Samples/resource-manager-python-resources-and-groups/blob/master/example.py#L48
The text was updated successfully, but these errors were encountered: