So I have the following Python3 script to list all virtual machines.
import os, json
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id="xxx",
secret="xxx",
tenant="xxx"
)
resource_client = ResourceManagementClient(credentials, "my-subscription")
compute_client = ComputeManagementClient(credentials, "my-subscription")
network_client = NetworkManagementClient(credentials, "my-subscription")
for vm in compute_client.virtual_machines.list_all():
print("\tVM: {}".format(vm.name))
but for some reason, I get the following error:
Traceback (most recent call last):
File "/Users/me/a/azure-test.py", line 17, in <module>
for vm in compute_client.virtual_machines.list_all():
...
File "/usr/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'
Am I doing something wrong?