Search code examples
pythonazureazure-cliazureclicredential

How to resolve issue of AzureCliCredential?


The following is my code and in linux I have logged in to azure via az login but when I try to run the below code it gives me an error that

Traceback (most recent call last): File "scan.py", line 1, in from azure.identity import AzureCliCredential

I also installed the pip install azure-identity but its still the same.

#CODE#

from azure.identity import AzureCliCredential
from azure.mgmt.subscription import SubscriptionClient
import json


credential = AzureCliCredential()
subscription_client = SubscriptionClient(credential)
sub_list = subscription_client.subscriptions.list()

for sub in list(sub_list):
    subs_id = sub.subscription_id
    print(subs_id)

Solution

  • Glad @Ghostrider that you had resolved the issue yourself.

    As you did not mention what version of python, you're using earlier, but for now resolved by using python 3.

    I also run this code in my local VS Code with the Python 3.9 Version and got the successful result:

    VSCodeRun

    Also, observed the packages present in the code that the package azure-identity is supported from Python Version 3.6 or the latest versions, as given in the Python Packages Library Official Site.