Closed
Description
- Package Name: azure.mgmt.resource
- Package Version: 15.0.0
- Operating System: Archlinux
- Python Version: 3.9.1
Describe the bug
Attribute Error duing resource list
To Reproduce
Steps to reproduce the behavior:
main.py:
#!/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:
<msrestazure.azure_active_directory.ServicePrincipalCredentials object at 0x7f556e3dc520>
<iterator object azure.core.paging.ItemPaged at 0x7f556d067790>
Traceback (most recent call last):
File "/home/masterkorp/Documents/RenaltyXAi/repos/docker-grafana/./get-az-resouces.py", line 35, in <module>
main()
File "/home/masterkorp/Documents/RenaltyXAi/repos/docker-grafana/./get-az-resouces.py", line 32, in main
for item in client.resource_groups.list():
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/paging.py", line 129, in __next__
return next(self._page_iterator)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/paging.py", line 76, in __next__
self._response = self._get_next(self.continuation_token)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/mgmt/resource/resources/v2020_06_01/operations/_resource_groups_operations.py", line 580, in get_next
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_base.py", line 211, in run
return first_node.send(pipeline_request) # type: ignore
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/mgmt/core/policies/_base.py", line 47, in send
response = self.next.send(request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
[Previous line repeated 1 more time]
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/policies/_redirect.py", line 158, in send
response = self.next.send(request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/policies/_retry.py", line 435, in send
response = self.next.send(request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_base.py", line 69, in send
_await_result(self._policy.on_request, request)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/_tools.py", line 29, in await_result
result = func(*args, **kwargs)
File "/home/masterkorp/.local/lib/python3.9/site-packages/azure/core/pipeline/policies/_authentication.py", line 93, in on_request
self._token = self._credential.get_token(*self._scopes)
AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
chlowell commentedon Feb 24, 2021
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:
I showed creating ClientSecretCredential above to demonstrate the difference vs. ServicePrincipalCredentials. However, using EnvironmentCredential is simpler (it will read the same variables):
(Related: #14919)
ghost commentedon Feb 24, 2021
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @darshanhs90, @AshishGargMicrosoft.
Issue Details
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
Mgmt
,Resource Authorization
,Service Attention
,bug
,customer-reported
jongio commentedon Mar 1, 2021
I'm looking into this for an update.
4 remaining items