Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing locations in Azure using Python Azure SDK error

I am trying out the listing of different locations in Azure using Python Azure SDKs from Windows machine Below is the error :

enter image description here

Please see my code :

import os
import sys
import logging
from azure import *
from azure.servicemanagement import *


subscription_id = 'XXXXXX-XXXXX-XXXXX-XXXXX-XXXXXXXXXXXX'
certificate_path = '\.pem'

   sms = ServiceManagementService(subscription_id, certificate_path)
   result = sms.list_subscriptions()
   for location in result:
    print(location.name)

enter image description here

like image 597
Kiran Avatar asked May 25 '26 09:05

Kiran


1 Answers

I hope this helps, you can use the new api to list locations, you don't need to use a certificate :).

    from azure.common.credentials import ServicePrincipalCredentials
    from azure.mgmt.subscription import SubscriptionClient


    subscription_id = "11111111-1111-1111-1111-111111111111"
    client_id = "11111111-1111-1111-1111-111111111111"
    secret = "11111111-1111-1111-1111-111111111111"
    tenant_id = "11111111-1111-1111-1111-111111111111"

    creds = ServicePrincipalCredentials(client_id=client_id, secret=secret,                 
    tenant=tenant_id)

    subscription_client = SubscriptionClient(creds)
    locations = subscription_client.subscriptions.list_locations(subscription_id)
    for location in locations:
        print(location.name)

generating client ID and secret can be done by running the cli command:

    az ad sp create-for-rbac --sdk-auth > my.azureauth
like image 107
darc Avatar answered May 27 '26 22:05

darc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!