我正在尝试使用 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了解更多信息。
关于python - 如何使用Python Azure SDK创建标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36593991/