def requestQcloud(module, action, secretId, secretKey, params): module = module ''' action 对应接口的接口名,请参考产品文档上对应接口的接口名 ''' action = action config = { 'Region': 'ap-beijing', 'secretId': secretId, 'secretKey': secretKey, 'method': 'get' } ''' params 请求参数,请参考产品文档上对应接口的说明 ''' params = { 'Version': "2017-03-12", } # if Offset is not None: # params['Offset'] = Offset # if Limit is not None: # params['Limit'] = Limit try: service = QcloudApi(module, config) # 生成请求的URL,不发起请求 service.generateUrl(action, params) print service.generateUrl(action, params) # 调用接口,发起请求 print params result = service.call(action, params) print service.call(action, params) return result except Exception, e: traceback.print_exc() print 'exception:', e
def transTX(srcStr, srcL, tarL): with open("config.json", "r") as confile: configJson = json.load(confile) module = 'tmt' action = 'TextTranslate' config = { 'Region': 'gz', 'secretId': configJson["secretId"], 'secretKey': configJson["secretKey"] } action_params = {'sourceText': srcStr, 'source': srcL, 'target': tarL} try: service = QcloudApi(module, config) service.generateUrl(action, action_params) # print(service.generateUrl(action, action_params)) str_json = str(service.call(action, action_params), encoding="utf-8") # print(str_json) datarturn = json.loads(str_json) return datarturn['targetText'] except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def get_download_link(params, config): service = QcloudApi('cdn', config) service.setRequestMethod('post') service.generateUrl('GetCdnLogList', params) req_qcloud = service.call('GetCdnLogList', params).decode() qcloud_output = process_output(req_qcloud) # 如果获取列表失败,则尝试3次 if qcloud_output[0] is False: qcloud_output_loop = 0 while qcloud_output_loop > 3: qcloud_output = process_output( service.call('GetCdnLogList', params).decode()) if qcloud_output[0] is not False: break qcloud_output_loop += 1 return qcloud_output
def create_lb_jtq(self): module = 'lb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' action = 'CreateForwardLBSeventhLayerListeners' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } action_params = { 'Version': '2017-03-12', 'loadBalancerId': self.lb_id, #监听哪个服务的端口 这里监听80端口 'listeners.0.loadBalancerPort': '80', 'listeners.0.protocol': '1', 'listeners.0.listenerName': 'liyanliang' } # 接口参数 try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) print(eval(res)) print('监听器创建成功') except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def getContentTranscode(url): ''' parameter: url:The target url return: data ''' module = 'wenzhi' action = 'ContentTranscode' region = "sz" path = Util.getDataPath("keys/keys.txt") with open(path) as f: secretId = f.readline().strip('\n') secretKey = f.readline().strip('\n') config = { 'Region': region, 'secretId': secretId, 'secretKey': secretKey} action_params = { 'url':url } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) result = service.call(action, action_params) print(result) except Exception as e: print('traceback.format_exc():\n%s' % traceback.format_exc()) if(result == None): return data = json.loads(result.decode('utf-8')) if(result != None and data["code"] != 0): return None else: return data
def get_record_id(domain, sub_domain, record_type): module = 'cns' action = 'RecordList' config = { 'Region': 'ap-beijing', 'secretId': SECRET_ID, 'secretKey': SECRET_KEY, 'method': 'GET', 'SignatureMethod': 'HmacSHA256' } action_params = { 'domain': domain, 'subDomain': sub_domain, 'recordType': record_type, } result = None try: service = QcloudApi(module, config) logging.debug("Get Query URL: %s" % service.generateUrl(action, action_params)) result = service.call(action, action_params) result = str(result, encoding='utf-8') result = json.loads(result) except Exception: import traceback logging.error(traceback.format_exc()) if result is None or len(result['data']['records']) != 1: return None, None return result['data']['records'][0]['id'], result['data']['records'][0][ 'value']
def cz_cvm_password(self): in_id = select_insid() module = 'cvm' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' #重置密码 action = 'ResetInstancesPassword' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 action_params = { # API 版本号 'Version': '2017-03-12', 'InstanceIds.0': in_id, 'Password': '******', 'ForceStop': True } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) print(eval(res)) cz_mima.mima.append(action_params['Password']) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def select_insid(): ''' module: 设置需要加载的模块 已有的模块列表: cvm 对应 cvm.api.qcloud.com cdb 对应 cdb.api.qcloud.com lb 对应 lb.api.qcloud.com trade 对应 trade.api.qcloud.com sec 对应 csec.api.qcloud.com image 对应 image.api.qcloud.com monitor 对应 monitor.api.qcloud.com cdn 对应 cdn.api.qcloud.com ''' module = 'cvm' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' action = 'DescribeInstances' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 action_params = { #API 版本号 'Version':'2017-03-12', 'Filters':[ { 'Name':'zone', 'Values':['ap-beijing-3'] }, #这里加Filter条件 ], 'Limit':1, } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res=service.call(action, action_params) import json temp=str(res).strip('b') tmp=json.loads(temp.replace('\'','')) instans_id = tmp['Response']['InstanceSet'][0]['InstanceId'] instans_id=str(instans_id) print('查询负载均衡成功,它的id是%s'%instans_id) return instans_id except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def getInstances(module, action, secretId, secretKey, Version, Offset, Limit): print 'module : %s ' % module print 'action : %s ' % action print 'secretId : %s ' % secretId print 'secretKey : %s ' % secretKey print 'Version : %s ' % Version print 'Offset : %s ' % Offset print 'Limit : %s ' % Limit module = module ''' action 对应接口的接口名,请参考产品文档上对应接口的接口名 ''' action = action config = { 'Region': 'ap-beijing', 'secretId': secretId, 'secretKey': secretKey, 'method': 'get' } ''' params 请求参数,请参考产品文档上对应接口的说明 ''' params = { 'Version': "2017-03-12", } if Offset is not None: params['Offset'] = Offset if Limit is not None: params['Limit'] = Limit try: print 'config : %s ' % config service = QcloudApi(module, config) # 生成请求的URL,不发起请求 print 'service : %s ' % service print 'params : %s ' % params service.generateUrl(action, params) # print service.generateUrl(action, params) # 调用接口,发起请求 print params result = service.call(action, params) print service.call(action, params) return result except Exception, e: traceback.print_exc() print 'exception:', e
class TX_CNS: def __init__(self, secretId, secretKey, domain): module = 'cns' config = {'secretId': secretId, 'secretKey': secretKey} self.service = QcloudApi(module, config) self.domain = domain def get_record_id(self, subDomain): action = 'RecordList' action_params = { 'domain': self.domain, 'subDomain': subDomain, } try: self.service.generateUrl(action, action_params) res = json.loads(self.service.call(action, action_params)) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc()) return res['data']['records'][0]['id'] def modify_record(self, subDomain, recordId, value): action = 'RecordModify' action_params = { 'domain': self.domain, 'subDomain': subDomain, 'recordId': recordId, 'recordType': 'A', 'recordLine': '默认', 'value': str(value) } try: self.service.generateUrl(action, action_params) res = json.loads(self.service.call(action, action_params)) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc()) return res['code'], res['codeDesc']
def dmknlp(dmk): module = "wenzhi" action = "TextSentiment" config = {"Region": "sh", "secretId": "", "secretKey": "", "method": "get"} params = {"content": dmk, "type": 4} service = QcloudApi(module, config) print service.generateUrl(action, params) s = service.call(action, params) try: dejson = json.loads(s) negative = dejson["negative"] positive = dejson["positive"] emotion = (positive - negative) * 5 return emotion except Exception, e: print "exception:", e return 0
def _old_request(self) -> dict: """ 使用老版 sdk 发送请求,返回响应结果 :return: 包含响应结果的字典 """ # 传入密钥,获取客户端 secret_params = ({ 'secretId': self._ak_sk[0], 'secretKey': self._ak_sk[1] }) client = QcloudApi(self._interface['module'], secret_params) client.generateUrl(self._interface['name'], self._params) # 进行请求,得到响应 try: resp = client.call(self._interface['name'], self._params) except TencentCloudSDKException as e: if not e.requestId: raise CloudNativeSDKError(f'client error: {e.message}') return self._build_error_data(e) # 将结果反序列化为对象并输出 return safe_json_loads(resp)
def Post(self): module = 'wenzhi' action = 'TextDependency' config = { 'method': 'GET', 'Region': 'ap-shanghai', 'secretId': 'AKID67xY021Y6NXXM2vJv79KLBtLcjhWI3zk', 'secretKey': 'CJPLzYUIF4892MNH1e9ScdWUI1c1IWce', 'SignatureMethod': 'HmacSHA1' } params = {'content': self._content, 'code': 0x00200000, 'type': 4} service = QcloudApi(module, config) url = service.generateUrl(action, params) response = service.call(action, params) self._responses = json.loads(response)['keywords']
def get_monitor(self, region, action_params): self.config["Region"] = region self.action_params = action_params module = "monitor" action = "GetMonitorData" try: service = QcloudApi(module, self.config) print(service.generateUrl(action, self.action_params)) result = json.loads(service.call(action, self.action_params)) logger.info(result) if result.get("code") == 0: return result logger.error("查询监控信息失败。错误信息:" + result.get("message").encode("utf-8")) except Exception: logger.exception("查询监控信息出现异常。")
def active_region(self): module = 'cvm' action = 'DescribeRegions' config = { 'secretId': self.secretId, 'secretKey': self.secretKey } action_params = { } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) print(service.call(action, action_params)) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def update_security_group(config, sgID, index, policys): action = 'ModifySingleSecurityGroupPolicy' action_params = { 'sgId':sgID, 'direction':'ingress', 'index':index, 'policys':policys, } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) print(service.call(action, action_params)) except Exception as e: import traceback log(traceback.format_exc())
def change_ip(record_obj): module = 'cns' action = 'RecordModify' config = { 'Region': 'ap-beijing', 'secretId': SECRET_ID, 'secretKey': SECRET_KEY, 'method': 'GET', 'SignatureMethod': 'HmacSHA256' } action_params = { 'domain': record_obj['domain'], 'recordId': record_obj['id'], 'subDomain': record_obj['sub_domain'], 'recordType': record_obj['type'], 'recordLine': '默认', 'value': record_obj['new_ip'] } try: service = QcloudApi(module, config) logging.debug("Get Query URL: %s" % service.generateUrl(action, action_params)) result = service.call(action, action_params) result = str(result, encoding='utf-8') result = json.loads(result) logging.debug(result) if result['code'] != 0: logging.error("Code : %s" % result['code']) logging.error("Message: %s" % result['message']) return False else: logging.debug("Record id : %s" % result['data']['record']['id']) logging.debug("Record status: %s" % result['data']['record']['status']) logging.debug("Record value : %s" % result['data']['record']['value']) logging.debug("Record name : %s" % result['data']['record']['name']) logging.debug("Record weight: %s" % result['data']['record']['weight']) return True except Exception: import traceback logging.error(traceback.format_exc()) return False
def get_project(self): try: service = QcloudApi(self.module, self.config) # 请求前可以通过下面几个方法重新设置请求的secretId/secretKey/Region/method/SignatureMethod参数 # 重新设置请求的Region # service.setRegion('ap-shanghai') # 打印生成的请求URL,不发起请求 print(service.generateUrl(self.action, self.action_params)) # 调用接口,发起请求,并打印返回结果 result = json.loads( service.call(self.action, self.action_params).decode()) result['results'] = result.pop('data') return result except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def req_url_generate(): from app.utils.personal_config import tencent_secret_id, tencent_secret_key, region_lst module = 'cvm' action = 'DescribeInstances' config = { 'secretId': tencent_secret_id, 'secretKey': tencent_secret_key, 'method': 'get' } params = { 'SignatureMethod': 'HmacSHA1', } req_url_lst = [] for region in region_lst: config['Region'] = region service = QcloudApi(module, config) req_url_lst.append(service.generateUrl(action, params)) return req_url_lst
def bd_clb(self, instans_id): print(instans_id) self.instans_id = instans_id print(self.instans_id, '-----------instanceid ') module = 'lb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' action = 'RegisterInstancesWithForwardLBSeventhListener' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # import action_params = { 'Version': '2017-03-12', #负载均衡id 'loadBalancerId': self.lb_id, #监听器id 'listenerId': self.listen_id, #云主机id 'backends.0.instanceId': self.instans_id, 'backends.0.weight': 10, #监听端口 'backends.0.port': 80, } # 接口参数 try: print('绑定中......') service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) print(eval(res)) print('负载均衡绑定云主机成功') except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def gw_ip(self): ''' 给数据库指定公网ip :return: ''' # 给加一个安全组 self.module = 'cdb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' self.action = 'OpenWanService' self.config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } ''' config: 云API的公共参数 ''' # 接口参数 self.action_params = { 'Version': '2017-03-12', 'instanceId': self.instance_id } print(self.action_params['instanceId']) try: service = QcloudApi(self.module, self.config) print(service.generateUrl(self.action, self.action_params)) res = service.call(self.action, self.action_params) print(eval(res)) except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def getKeyword(title, content, channel="CHnews_news_tech"): ''' parameter: title:The title of news content:The content of news channel:The channel that the news belongs to.(Optional, the default value is tech) return: data:The result in json format.Fields contained:keyword,score,type use data['keyword'] to access ''' module = 'wenzhi' action = 'TextKeywords' region = "sz" result = None path = Util.getDataPath("keys/keys.txt") with open(path) as f: secretId = f.readline().strip('\n') secretKey = f.readline().strip('\n') config = { 'Region': region, 'secretId': secretId, 'secretKey': secretKey} action_params = { 'title': title, 'content':content } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) result = service.call(action, action_params) print(result) except Exception as e: print('traceback.format_exc():\n%s' % traceback.format_exc()) if(result == None): return data = json.loads(result.decode('utf-8')) if(result != None and data["code"] != 0): return None else: return data['keywords']
def select_id(self): ''' 获取instance_id 来给数据库开通实例外网访问 :return: ''' self.module = 'cdb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' self.action = 'DescribeDBInstances' ''' config: 云API的公共参数 ''' self.config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 self.action_params = { 'Version': '2017-03-12', 'InstanceIds.0': 'cdb-c3sa3yg3' } # try: service = QcloudApi(self.module, self.config) print(service.generateUrl(self.action, self.action_params)) res = service.call(self.action, self.action_params) print(res) temp = str(res).strip('b') import json tmp = json.loads(temp.replace('\'', '')) self.instance_id = tmp['data']['items'][0]['instanceId'] print(self.instance_id) except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def create_clb(self): module = 'lb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' action = 'CreateLoadBalancer' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 action_params = { 'Version': '2017-03-12', #公网 'loadBalancerType': '2', #应用型 'forward': '1', # 'loadBalancerName': 'clb_one', 'number': '1' } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) print(eval(res)) print('睡眠10秒,~等待~ 负载均衡创建成功') time.sleep(10) print('创建成功') except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def zf_rules(self): module = 'lb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' action = 'CreateForwardLBListenerRules' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # import action_params = { 'Version': '2017-03-12', # 负载均衡id 'loadBalancerId': self.lb_id, # 监听器id 'listenerId': self.listen_id, 'rules.0.domain': 'www.liyanliang.com', 'rules.0.url': '/index.html', 'rules.0.sessionExpire': '50' } #接口参数 try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) print(eval(res)) #开始睡眠 print('转发路路由规则创建成功,开始等待五秒') time.sleep(5) print('创建成功') except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def select_lb_id(self): ''' 查到指定负载均衡的id :return: ''' module = 'lb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' action = 'DescribeLoadBalancers' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 action_params = { 'Version': '2017-03-12', # 'loadBalancerType':'2' 'forward': '-1' } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) temp = str(res).strip('b') import json tmp = json.loads(temp.replace('\'', '')) print(tmp) self.lb_id = tmp['loadBalancerSet'][0]['loadBalancerId'] print(self.lb_id, 'lbid is success ') except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def create_cdb(self): self.module = 'cdb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' self.action = 'CreateDBInstanceHour' ''' config: 云API的公共参数 ''' self.config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 self.action_params = { 'Version': '2017-03-12', 'cdbType': 'CUSTOM ', 'engineVersion': '5.6', 'goodsNum': '1', 'memory': '2000', 'volume': '100' } # try: service = QcloudApi(self.module, self.config) print(service.generateUrl(self.action, self.action_params)) res = service.call(self.action, self.action_params) res1 = eval(res) print(res1) self.in_ids = res1['data']['instanceIds'] except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def select_listenerld(self): module = 'lb' action = 'DescribeForwardLBListeners' config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } action_params = {'Version': '2017-03-12', 'loadBalancerId': self.lb_id} # 接口参数 try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) res = service.call(action, action_params) res = json.loads(res.decode()) self.listen_id = res['listenerSet'][0]['listenerId'] print(self.listen_id, '-----------------监听id---------------') except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def safe_group(self): ''' 给加一个安全组 :return: ''' self.module = 'dfw' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' self.action = 'CreateSecurityGroup' ''' config: 云API的公共参数 ''' self.config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 self.action_params = { 'Version': '2017-03-12', 'sgName': 'safe_group_one' } # try: service = QcloudApi(self.module, self.config) print(service.generateUrl(self.action, self.action_params)) res = service.call(self.action, self.action_params) print(eval(res)) except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
def chush_cdb(self): self.module = 'cdb' ''' action: 对应接口的接口名,请参考产品 API 文档上对应接口的接口名 ''' self.action = 'InitDBInstances' ''' config: 云API的公共参数 ''' self.config = { 'Region': 'ap-beijing', 'secretId': 'AKIDTp13vccxugHgv0QjOsBJG2d2HMH0Lv79', 'secretKey': '2vfFetxqZ7UghWBfy51nZROK5f5KOIBt', } # 接口参数 self.action_params = { 'action': 'InitDBInstances', 'Version': '2017-03-12', 'instanceIds': self.in_ids, 'newPassword': '******', 'parameters': [{ 'name': 'character_set_server', 'value': 'utf8' }], } try: service = QcloudApi(self.module, self.config) print(type(service.generateUrl(self.action, self.action_params))) res = service.call(self.action, self.action_params) print(eval(res)) except Exception as e: print(e) import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())
action: 对应接口的接口名,请参考wiki文档上对应接口的接口名 ''' action = 'DescribeInstances' ''' config: 云API的公共参数 ''' config = { 'Region': 'ap-guangzhou', 'secretId': '您的secretId', 'secretKey': '您的secretKey', } # 接口参数 action_params = { 'Version': '2017-03-12', 'Filters': [{ 'Name': 'zone', 'Values': ['ap-guangzhou-1', 'ap-guangzhou-2'] }], 'limit': 1, } try: service = QcloudApi(module, config) print(service.generateUrl(action, action_params)) print(service.call(action, action_params)) except Exception as e: import traceback print('traceback.format_exc():\n%s' % traceback.format_exc())