1

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)
Ghost rider
  • 43
  • 1
  • 9

1 Answers1

0

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.

  • I was running the file with normal python (filename) command so mostly it was some older 2 version of python , when I did python3 (filename) it started to work. – Ghost rider Jul 12 '22 at 19:07
  • Yes @Ghostrider, Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. –  Jul 13 '22 at 03:29
  • Thanks Hari will keep this into account while making future deployments. – Ghost rider Jul 13 '22 at 04:01