使用Python Azure SDK错误列出Azure中的位置 [英] Listing locations in Azure using Python Azure SDK error

查看:59
本文介绍了使用Python Azure SDK错误列出Azure中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Windows计算机上的Python Azure SDK列出Azure中不同位置的列表下面是错误:

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

请参阅我的代码:

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)

推荐答案

我希望这会有所帮助,您可以使用新的api列出位置,而无需使用证书:).

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)

可以通过运行cli命令来生成客户端ID和密码:

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

    az ad sp create-for-rbac --sdk-auth > my.azureauth

这篇关于使用Python Azure SDK错误列出Azure中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆