官方SDK文档:https://github.com/TencentCloud/tencentcloud-sdk-python

安装

  1. pip install tencentcloud-sdk-python

使用

  1. # -*- coding: utf-8 -*-
  2. from tencentcloud.common import credential
  3. from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
  4. # 导入对应产品模块的client models。
  5. from tencentcloud.cvm.v20170312 import cvm_client, models
  6. try:
  7. # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
  8. cred = credential.Credential("secretId", "secretKey")
  9. # 实例化要请求产品(以cvm为例)的client对象
  10. client = cvm_client.CvmClient(cred, "ap-shanghai")
  11. # 实例化一个请求对象
  12. req = models.DescribeZonesRequest()
  13. # 通过client对象调用想要访问的接口,需要传入请求对象
  14. resp = client.DescribeZones(req)
  15. # 输出json格式的字符串回包
  16. print(resp.to_json_string())
  17. except TencentCloudSDKException as err:
  18. print(err)