def init_client(self, region): self._region = region if True: try: cred = credential.Credential( self._tencent_id, self._tencent_key) if self._region in self._regions: endpoint = self._api+'.tencentcloudapi.com' hp=http_profile.HttpProfile() hp.endpoint = endpoint cp = client_profile.ClientProfile() cp.httpProfile = hp self._client = clb_client.ClbClient(cred, region, cp) # if region.find('ap-shenzhen-fsi'): # endpoint = self._api+'.tencentcloudapi.com' # hp=http_profile.HttpProfile() # hp.endpoint = endpoint # cp = client_profile.ClientProfile() # cp.httpProfile = hp # self._client = clb_client.ClbClient(cred, "ap-shenzhen-fsi", cp) # else: # print self._region # self._client = clb_client.ClbClient(cred, self._region) except TencentCloudSDKException as err: print(err) except Exception as e: print str(e)
def __init__(self, region, page, Limit): self.region = region self.Offset = ((int(page) - 1) * Limit) if page else None self.Limit = Limit if Limit else None secretId, secretKey = get_config_secret() try: self.secretId = secretId self.secretKey = secretKey # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey cred = credential.Credential(secretId=self.secretId, secretKey=self.secretKey) self.cred = cred # 实例化一个client选项,可选的,没有特殊需求可以跳过。 hp = http_profile.HttpProfile() hp.reqMethod = "POST" cp = client_profile.ClientProfile() cp.signMethod = "TC3-HMAC-SHA256" cp.httpProfile = hp self.cp = cp self.client = cvm_client.CvmClient(self.cred, self.region, self.cp) self.monitor = monitor_client.MonitorClient(credential=self.cred, region=self.region) except TencentCloudSDKException as e: logger.error(e) logger.error( 'there is wrong in getting tencent api credential init')
def init_client(self,region): self._region=region if True: try: cred = credential.Credential(self._tencent_id, self._tencent_key) if self._region: region=self._region if region.find('fsi'): endpoint=self._api+'.'+region+'.tencentcloudapi.com' hp=http_profile.HttpProfile() hp.endpoint = endpoint cp=client_profile.ClientProfile() cp.httpProfile = hp self._client = vpc_client.VpcClient(cred,region,cp) else: self._client = vpc_client.VpcClient(cred,self._region) except TencentCloudSDKException as err: print(err) except Exception as e: print str(e)
# -*- coding: utf-8 -*- import os from tencentcloud.common import credential from tencentcloud.common.profile import client_profile from tencentcloud.common.profile import http_profile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException # 导入对应产品模块的client models。 from tencentcloud.cvm.v20170312 import cvm_client, models try: # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"), os.environ.get("TENCENTCLOUD_SECRET_KEY")) # 实例化一个client选项,可选的,没有特殊需求可以跳过。 hp = http_profile.HttpProfile() # 如果需要指定proxy访问接口,可以按照如下方式初始化hp # hp = http_profile.HttpProfile(proxy="http://用户名:密码@代理IP:代理端口") hp.reqMethod = "POST" cp = client_profile.ClientProfile() cp.signMethod = "TC3-HMAC-SHA256" cp.httpProfile = hp # 实例化要请求产品(以cvm为例)的client对象 client = cvm_client.CvmClient(cred, "ap-guangzhou", cp) # 实例化一个请求对象 req = models.DescribeZonesRequest() # 通过client对象调用想要访问的接口,需要传入请求对象 resp = client.DescribeZones(req) # 输出json格式的字符串回包