gpt4 book ai didi

azure - Azure API 脚本列表

转载 作者:行者123 更新时间:2023-12-03 06:22:00 24 4
gpt4 key购买 nike

在尝试收集我使用的所有 AWS API 时:

> import boto3

# Create a new session
session = boto3.Session()

# Get a list of available services
available_services = session.get_available_services()


# Write the list to a file
with open('aws_services.txt', 'w') as f:
for service in sorted(available_services):
f.write(service + '\n')

在 Azure 中是否有类似的做法?

谢谢!

最佳答案

我在我的环境中进行了尝试并得到了以下结果:

Is/What is a similar way of doing it in Azure?

要获取可用的 Azure 服务并将其存储在文本文件中,您可以使用适用于 Python 的 Azure SDK 以及 azure-mgmt-resource azure-identity 包。

首先,尝试使用终端中的命令使用您的 Azure 帐户登录:

命令:

az-login

代码:

from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient

# Create a ResourceManagementClient using your Azure credentials
credential = DefaultAzureCredential()
subscription_id = 'Your azure subscription ID'
resource_client = ResourceManagementClient(credential, subscription_id)

# Retrieve the list of Azure services
providers = resource_client.providers.list()

# Write the list of services to a text file
with open('azure_services.txt', 'w') as f:
for provider in providers:
f.write(provider.namespace + '\n')

执行上述代码并获取可用服务并以 azure_service.txt 格式存储。

文本文件。

enter image description here

如果您需要获取不带文本格式的可用服务,您可以使用以下代码:

命令:

from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient

credential = DefaultAzureCredential()
subscription_id = 'Your azure subscription ID'
resource_client = ResourceManagementClient(credential, subscription_id)
providers = resource_client.providers.list()
for provider in providers:
print(provider.namespace)

输出: enter image description here

引用: azure-samples-python-management/manage_providers.py at main · Azure-Samples/azure-samples-python-management (github.com)

关于azure - Azure API 脚本列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75834995/

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