【问题标题】:How to create Traffic Manager Profile by using python Azure SDK and It Endpoints?如何使用 python Azure SDK 和 It Endpoints 创建流量管理器配置文件?
【发布时间】:2021-08-02 09:51:34
【问题描述】:
# Obtain the management object for resources, using the credentials from the CLI login.
tm_client = TrafficManagerManagementClient(credentials, subscription_id)

result = tm_client.profiles.create_or_update(   
    RESOURCE_GROUP_NAME,    
    'new_tm_profile',    
    {    
        'location': 'Global',    
        'profile_status': 'Enabled',     
        'traffic_routing_method': 'Priority',     
        'dns_config':      
        {      
          'relative_name': 'tmtest',     
          'ttl': 60      
        },     
        'monitor_config':     
        {      
          'protocol': 'HTTPS',     
          'port': 80,       
          'path': '/'          
        }               
    }                
    )               
           
print(result.id)              

它会抛出这个错误:

Traceback (most recent call last):
  File "c:/Users/kumarreddy/Downloads/BOS_5Y_DATA/Working_Python_Ansible_Azure/Azure_VM_DB_Python/tm_profile.py", line 48, in <module>
    result = tm_client.profiles.create_or_update(
  File "C:\Python38-32\lib\site-packages\azure\mgmt\trafficmanager\operations\profiles_operations.py", line 349, in create_or_update
    raise exp
msrestazure.azure_exceptions.CloudError: 400 Client Error: Bad Request for url: https://management.azure.com/subscriptions/02ac19d2-71ae-471d-b697-97daef2db017/resourceGroups/tm_resgroup/providers/Microsoft.Network/trafficmanagerprofiles/new_tm_profile?api-version=2017-05-01

【问题讨论】:

    标签: python azure azure-sdk-python azure-traffic-manager


    【解决方案1】:

    根据此{"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}} 错误消息,问题似乎是因为AzureCliCredential()。您需要设置 Azure CLI 并通过运行 az login 对 Azure 进行身份验证。

    您可以使用DefaultAzureCredential 与 SDK 管理库来检查身份验证失败的原因。

    Python

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.resource import SubscriptionClient
    
    credential = DefaultAzureCredential()
    subscription_client = SubscriptionClient(credential)
    
    sub_list = subscription_client.subscriptions.list()
    print(list(sub_list))
    

    可以参考Using DefaultAzureCredential with SDK management librariesAdd endpoints in Traffic Manager using python Azure SDK

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多