參考:https://cloud.tencent.com/document/product/494/7244
pip install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python
cred有兩種方式。我這裏用第一種方式,直接寫ak sk就可以了
import os from tencentcloud.common import credential from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.cvm.v20170312 import cvm_client, models try: # 爲了保護密鑰安全,建議將密鑰設置在環境變量中或者配置文件中,請參考本文憑證管理章節。 # 硬編碼密鑰到代碼中有可能隨代碼泄露而暴露,有安全隱患,並不推薦。 # cred = credential.Credential("secretId", "secretKey") cred = credential.Credential( os.environ.get("TENCENTCLOUD_SECRET_ID"), os.environ.get("TENCENTCLOUD_SECRET_KEY")) client = cvm_client.CvmClient(cred, "ap-shanghai") req = models.DescribeInstancesRequest() resp = client.DescribeInstances(req) print(resp.to_json_string()) except TencentCloudSDKException as err: print(err)