python - 如何使用Python Azure SDK创建标签?

标签 python azure azure-sdk-python

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

def __update_tags(self):
    username = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb8e889e89bb838281d5989496" rel="noreferrer noopener nofollow">[email protected]</a>'
    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'

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

最佳答案

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

resource_client = ResourceManagementClient(
ResourceManagementClientConfiguration(
    credentials,
    subscription_id
)

检查here了解更多信息。

更新: 确认导入 ResourceManagementClientConfiguration enter image description here

关于python - 如何使用Python Azure SDK创建标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36593991/

相关文章:

python - Unpickle具有向后兼容性的namedtuple(忽略附加属性)

python - 使用 DateTimeIndex 计算 Dataframe 中字符串的出现次数

python - 替换字符串的一部分 ' for\' 不起作用

azure - 与外部客户共享文件和数据

java - 要登录此应用程序,必须将帐户添加到 <TenantID> 目录

azure - 使用 python Azure SDK 在流量管理器中添加端点

python - 使用 PyGal,如何在悬停时在饼图本身上嵌入标签?

当没有定义或定义多个搜索字段时,Azure 搜索无法返回预期结果

azure - Python Azure SDK virtual_machines.run_command

azure - 托管身份未分配给资源