2016-04-13 22 views
1

Azot 2.0.0rc2'de Python kullanarak etiket oluşturmaya çalışıyorum.Etiketler nasıl kullanılır Python Azure SDK?

def __update_tags(self): 
    username = '[email protected]' 
    password = '[email protected]' 
    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') 

i gibi hata alıyorum bu kodu çalıştırarak üzerinde::

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

Herkes bu sorunu çözmek için fikir sahibi i kullanılan kod aşağıdadır.

cevap

0

Kodunuzda, subscription_id belirtildi, ancak kullanılmadı. Resource_client oluştururken subscription_id dosyasına ihtiyacınız var. Aşağıdaki kod ile "resource_client = ResourceManagementClient (kimlik = kimlik)" yerine edin: Daha fazla bilgi için

resource_client = ResourceManagementClient(
ResourceManagementClientConfiguration(
    credentials, 
    subscription_id 
) 

kontrol here.

Güncelleme: belgeleri (Resource Management ve Resource Management Authentication) göre onayla ithalat ResourceManagementClientConfiguration enter image description here

+0

ben bu şekilde denedim ama azure.mgmt.resource.resources gelen 'masmavi 2.0.0rc2 içinde ResourceManagementClientConfiguration içe' kullanılamaz. Lütfen bir kez doğrulayabilir misiniz? –

+0

@ramkumar ne demek yok? Ben azure.mgmt.resource.resources ithalat ResourceManagementClientConfiguration ** gelen ** benim tarafımdan onaylayabilirsiniz. Cevabımdaki güncellemeleri kontrol et. – forester123

0

dedi @ forester123 olarak, aşağıdaki gibi kod özetler.

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

username = '[email protected]' 
password = '[email protected]' 
subscription_id = '478-ytehn-47ds5-784aa-4758a' 

credentials = UserPassCredentials(username, password) 
resource_client = ResourceManagementClient(
    ResourceManagementClientConfiguration(
     credentials, 
     subscription_id 
    ) 
) 
İlgili konular