Skip to content

ServicePrincipalCredentials' object has no attribute 'get_token' #14059

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

Closed
kaimast opened this issue Sep 27, 2020 · 3 comments
Closed

ServicePrincipalCredentials' object has no attribute 'get_token' #14059

kaimast opened this issue Sep 27, 2020 · 3 comments
Assignees
Labels
Compute customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@kaimast
Copy link

kaimast commented Sep 27, 2020

I'm running the following code (derived from the examples).

import os

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient

def get_credentials():
    subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
    credentials = ServicePrincipalCredentials(
        client_id=os.environ['AZURE_CLIENT_ID'],
        secret=os.environ['AZURE_CLIENT_SECRET'],
        tenant=os.environ['AZURE_TENANT_ID']
    )
    return credentials, subscription_id

credentials, subscription_id = get_credentials()
compute_client = ComputeManagementClient(credentials, subscription_id)


print('\nList VMs in subscription')
for vm in compute_client.virtual_machines.list_all():
    print("\tVM: {}".format(vm.name))

However I get the following error. (and others seem too )

Traceback (most recent call last):
  File "./azure_generate_config.py", line 22, in <module>
    for vm in compute_client.virtual_machines.list_all():
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/paging.py", line 122, in __next__
    return next(self._page_iterator)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/paging.py", line 74, in __next__
    self._response = self._get_next(self.continuation_token)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/mgmt/compute/v2020_06_01/operations/_virtual_machines_operations.py", line 1115, in get_next
    pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_base.py", line 211, in run
    return first_node.send(pipeline_request)  # type: ignore
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_base.py", line 71, in send
    response = self.next.send(request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/mgmt/core/policies/_base.py", line 47, in send
    response = self.next.send(request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_base.py", line 71, in send
    response = self.next.send(request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_base.py", line 71, in send
    response = self.next.send(request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_base.py", line 71, in send
    response = self.next.send(request)
  [Previous line repeated 1 more time]
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/policies/_redirect.py", line 157, in send
    response = self.next.send(request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/policies/_retry.py", line 436, in send
    response = self.next.send(request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_base.py", line 69, in send
    _await_result(self._policy.on_request, request)
  File "/home/kai/.local/lib/python3.8/site-packages/azure/core/pipeline/_tools.py", line 29, in await_result
    result = func(*args, **kwargs)
  File "/home/kai/.local/lib/python3.8/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'

Any idea what am I doing wrong? Are the examples outdated?

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Sep 27, 2020
@xiangyan99 xiangyan99 added Compute Mgmt This issue is related to a management-plane library. labels Sep 28, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Sep 28, 2020
@changlong-liu
Copy link
Member

Hi @kaimast ,

Are you using the latest azure-mgmt-compute package?

The sample for latest package can be found here: https://github.com/Azure-Samples/azure-samples-python-management/tree/master/samples/compute

And here is a migration guide for using the latest sdk: https://github.com/Azure/azure-sdk-for-python/blob/master/doc/sphinx/python_mgmt_migration_guide.rst

@3ttp
Copy link

3ttp commented Sep 29, 2020 via email

@kaimast
Copy link
Author

kaimast commented Sep 30, 2020

Thank you! That sample works indeed :)

@kaimast kaimast closed this as completed Sep 30, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Compute customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

4 participants