azure-mgmt-resource library is not fully compatible with azure-identity. I have re-written the code as below and it works perfect
Reference: migration_guide.md
SP created with 'owner' permission in cli like: az ad sp create-for-rbac --name <name> --role Owner
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
credential = ServicePrincipalCredentials(client_id='your sp client id',secret='your sp secret',tenant='your tenant id')
compute_client = ComputeManagementClient(credential, 'your subscription id')
# List all Virtual Machines in the specified subscription
def list_virtual_machines():
for vm in compute_client.virtual_machines.list_all():
print(vm.name)
list_virtual_machines()