参考: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)
标签:tencentcloud,腾讯,client,tencent,import,服务器,cred,sdk From: https://www.cnblogs.com/machangwei-8/p/17920300.html