首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何调用查询实例列表api?

如何调用查询实例列表api?

提问于 2022-07-27 00:22:02
回答 1关注 0查看 186

# 解决腾讯自签名证书问题 message:[SSL: CERTIFICATE_VERIFY_FAILED]

import ssl

ssl._create_default_https_context=ssl._create_unverified_context

import json

from tencentcloud.common import credential

from tencentcloud.common.profile.client_profile import ClientProfile

from tencentcloud.common.profile.http_profile import HttpProfile

from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException

from tencentcloud.cvm.v20170312 import cvm_client, models

try:

# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密

# 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取

    cred = credential.Credential("AKID4vH3qlk865KK", "1ElYPvDnIEsI7wiWM")

# 实例化一个http选项,可选的,没有特殊需求可以跳过

    httpProfile = HttpProfile()

    httpProfile.endpoint = "cvm.tencentcloudapi.com"

# 实例化一个client选项,可选的,没有特殊需求可以跳过

    clientProfile = ClientProfile()

    clientProfile.httpProfile = httpProfile

# 实例化要请求产品的client对象,clientProfile是可选的

    client = cvm_client.CvmClient(cred, "", clientProfile)

# 实例化一个请求对象,每个接口都会对应一个request对象

    req = models.DescribeInstancesRequest()

    params = {

    }

    req.from_json_string(json.dumps(params))

# 返回的resp是一个DescribeInstancesResponse的实例,与请求对象对应

    resp = client.DescribeInstances(req)

# 输出json格式的字符串回包

print(resp.to_json_string())

except TencentCloudSDKException as err:

print(err)

代码如上 返回报错

[TencentCloudSDKException] code:ClientNetworkError message:HTTPSConnectionPool(host='cvm.tencentcloudapi.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1029: The handshake operation timed out'))) requestId:None

相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档