TencentCloud / tencentcloud-sdk-python

Tencent Cloud API 3.0 SDK for Python
Apache License 2.0
613 stars 251 forks source link

调用查询实例列表api报错 #137

Open JungleWolfz opened 2 years ago

JungleWolfz commented 2 years ago

代码如: `# 解决腾讯自签名证书问题 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("AKID4vHaTSE2hiz09A93dC512B4W9P3qlk865KK", "1ElYPvDna5bzPwC3oKS828a147PcUp7IEsI7wiWM")
# 实例化一个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

通过apiexplore调用 也报了后端服务错误 https://console.cloud.tencent.com/api/explorer?Product=cvm&Version=2017-03-12&Action=DescribeInstances

zqfan commented 2 years ago

这是证书报错,服务端的证书是没有问题的。如果你是自行编译安装的python,则可能是编译参数忘了加上ssl相关的配置了。另外就是考虑是否改动过机器上的ssl证书文件