如何使用Python Azure SDK创建标记?
我正在尝试使用Python在Azure 2.0.0rc2中创建标记。 以下是我使用的代码:如何使用Python Azure SDK创建标记?,python,azure,azure-sdk-python,Python,Azure,Azure Sdk Python,我正在尝试使用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=pass
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'
任何人都有办法解决这个问题。在您的代码中,指定了订阅id,但未使用。创建资源\u客户端时需要订阅\u id。请用以下代码替换“resource\u client=ResourceManagementClient(credentials=credentials)”:
resource_client = ResourceManagementClient(
ResourceManagementClientConfiguration(
credentials,
subscription_id
)
查看更多信息
更新:
确认导入ResourceManagementClientConfiguration
在代码中,指定了订阅id,但未使用。创建资源\u客户端时需要订阅\u id。请用以下代码替换“resource\u client=ResourceManagementClient(credentials=credentials)”:
resource_client = ResourceManagementClient(
ResourceManagementClientConfiguration(
credentials,
subscription_id
)
查看更多信息
更新:
确认导入ResourceManagementClientConfiguration
根据文档(和),如@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
)
)
根据文档(和),正如@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
)
)
我尝试过这种方法,但在azure 2.0.0rc2
中,从azure.mgmt.resource.resources导入ResourceManagementClientConfiguration
不可用。你能核实一下吗?@ramkumar你说不可用是什么意思?我可以从我这边确认,从azure.mgmt.resource.resources导入ResourceManagementClientConfiguration肯定有效。检查我回复中的更新。我已尝试过这种方法,但azure.mgmt.resource.resources导入ResourceManagementClientConfiguration中的azure 2.0.0rc2不可用。你能核实一下吗?@ramkumar你说不可用是什么意思?我可以从我这边确认,从azure.mgmt.resource.resources导入ResourceManagementClientConfiguration肯定有效。检查我回复中的更新。