1

我正在尝试使用 Python 在 Azure 2.0.0rc2 中创建标签。以下是我使用的代码:

def __update_tags(self):
    username = 'user@xyz.com'
    password = 'user@1234'
    subscription_id = '478-ytehn-47ds5-784aa-4758a'
    credentials = UserPassCredentials(username=username, password=password)
    resource_client = ResourceManagementClient(credentials=credentials)
    tag_operations = TagOperations(client=resource_client)
    tag_operations.create_or_update_value(tag_name='key_1', tag_value='val_1')

在运行此代码时,我收到如下错误:

    if self.client.credentials.subscription_id is not None:
AttributeError: 'UserPassCredentials' object has no attribute 'subscription_id'

任何人都有解决这个问题的想法。

4

2 回答 2

0

根据文档(资源管理资源管理身份验证),正如@forester123 所说,将代码总结如下。

from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource.resources import ResourceManagementClient, ResourceManagementClientConfiguration

username = 'user@xyz.com'
password = 'user@1234'
subscription_id = '478-ytehn-47ds5-784aa-4758a'

credentials = UserPassCredentials(username, password)
resource_client = ResourceManagementClient(
    ResourceManagementClientConfiguration(
        credentials,
        subscription_id
    )
)
于 2016-04-14T05:45:58.437 回答
0

在您的代码中,subscription_id 已指定但未使用。创建resource_client 时需要subscription_id。请将“ resource_client = ResourceManagementClient(credentials=credentials)”替换为以下代码:

resource_client = ResourceManagementClient(
ResourceManagementClientConfiguration(
    credentials,
    subscription_id
)

在这里查看更多信息。

更新:确认导入 ResourceManagementClientConfiguration 在此处输入图像描述

于 2016-04-13T09:31:53.217 回答