【发布时间】:2021-12-17 12:54:44
【问题描述】:
我无法读取所有 azure 存储帐户名称和密钥。
AZURE_TENANT_ID = '<string>'
AZURE_CLIENT_ID = '<string>'
AZURE_CLIENT_SECRET = '<string>'
AZURE_SUBSCRIPTION_ID = '<string>'
import os
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.storage.models import (
StorageAccountCreateParameters,
StorageAccountUpdateParameters,
Sku,
SkuName,
Kind
)
subscription_id = AZURE_SUBSCRIPTION_ID # your Azure Subscription Id
credentials = ServicePrincipalCredentials(
client_id=AZURE_CLIENT_ID,
secret=AZURE_CLIENT_SECRET,
tenant=AZURE_TENANT_ID
)
resource_client = ResourceManagementClient(credentials, subscription_id)
storage_client = StorageManagementClient(credentials, subscription_id)
print(resource_client,storage_client)
# Retrieve the list of resource groups
for item in storage_client.storage_accounts.list():
print_item(item)
在这段代码之后我得到了这个错误
AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'
在调试时我发现“storage_client.storage_accounts.list()”这个语句返回 azure.core.paging.ItemPaged 类的迭代器对象并且它一直返回相同的对象
请帮帮我
【问题讨论】:
标签: python azure cloud azure-storage