阿里云SLB Python-sdk 发表于 2018-04-24 阿里云SLB Python-sdk 范例1234567# 首先安装依赖 pip install aliyun-python-sdk-core# 如果您使用Python 3.x,执行以下命令,安装阿里云SDK核心库:# pip install aliyun-python-sdk-core-v3pip install aliyun-python-sdk-slb 12345678910111213141516171819202122232425262728#!/usr/bin/env python#coding=utf-8from aliyunsdkcore import clientfrom aliyunsdkslb.request.v20140515 import SetBackendServersRequestimport osclt = client.AcsClient('Access Key ID','Access Key Secret','SLB地区 eg:cn-hangzhou')ecsA = 'i-bp19cwe60vsu50ntf94b' # ECS后端实例IDecsB = 'i-bp13p7zpoi631xenhivo' # ECS后端实例IDecsA_weight = '0' # 权重ecsB_weight = '100'req_parm1 = "BackendServers"req_parm2 = [{"ServerId": ecsA, "Weight": ecsA_weight}, {"ServerId": ecsB, "Weight": ecsB_weight}]# 设置参数request = SetBackendServersRequest.SetBackendServersRequest()request.set_accept_format('json')request.add_query_param('LoadBalancerId', 'lb-bp1akx350m8jwt6snpjxs') # SLB 实例IDrequest.add_query_param('RegionId', 'cn-hangzhou')request.add_query_param(req_parm1, req_parm2)# 发起请求response = clt.do_action_with_exception(request)print (response) # 打印返回