gpt4 book ai didi

python - 列出给定 Azure 帐户的订阅

转载 作者:行者123 更新时间:2023-12-02 05:51:38 25 4
gpt4 key购买 nike

我正在尝试使用 azure-python-sdk 列出 Azure 帐户中的订阅。

我已点击文档中的此链接。

https://learn.microsoft.com/en-us/python/api/azure-mgmt-subscription/azure.mgmt.subscription.operations.subscriptionsoperations?view=azure-python#list-custom-headers-none--raw-false----operation-config-


from azure.mgmt.subscription import SubscriptionClient
from msrestazure.azure_active_directory import UserPassCredentials

credentials = UserPassCredentials(username='xxxx', password='xxxx')
sub_client = SubscriptionClient(credentials)
subs = [sub.as_dict() for sub in sub_client.subscriptions.list()]
print(subs)

它应该返回订阅列表。但是,每次尝试上述代码时,我都只看到返回空列表。有人可以帮忙吗?

最佳答案

试试这个代码,

def list_subscriptions():
try:
sub_client = get_client_from_cli_profile(SubscriptionClient)
except CLIError:
logger.info("Not logged in, running az login")
_run_az_cli_login()
sub_client = get_client_from_cli_profile(SubscriptionClient)

return [["Subscription_name", "Subscription ID"]] + [
[sub.display_name, sub.subscription_id]
for sub in sub_client.subscriptions.list()
]

您可以从here找到这个方便的工具。

关于python - 列出给定 Azure 帐户的订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com