Tencent Cloud KMS SDK for Python
raw JSON → 3.1.86 verified Sat May 09 auth: no python
Official Tencent Cloud SDK for the Key Management Service (KMS), providing APIs to create, manage, and use encryption keys. Current version: 3.1.86. Released monthly.
pip install tencentcloud-sdk-python-kms Common errors
error ModuleNotFoundError: No module named 'tencentcloud' ↓
cause Missing tencentcloud-sdk-python-common runtime dependency.
fix
pip install tencentcloud-sdk-python-kms (installs common automatically)
error tencentcloud.common.exception.TencentCloudSDKException: UnsupportedRegion ↓
cause Region passed to client is invalid or not supported by KMS.
fix
Use a valid region like 'ap-guangzhou', 'ap-beijing', etc.
Warnings
gotcha Region parameter must be set when creating client; if omitted, defaults to empty string and may cause errors. ↓
fix Always pass a valid region string to KmsClient constructor.
gotcha The kms_client module is generated and the class name is KmsClient with capital C, but users often write 'kmsclient'. ↓
fix Use 'kms_client.KmsClient' as shown in quickstart.
deprecated Old import path tencentcloud-sdk-python without -kms suffix is deprecated in favor of product-specific packages. ↓
fix Install tencentcloud-sdk-python-kms and import from tencentcloud.kms.
Imports
- KmsClient wrong
from tencentcloud.kms.v20190118.kms_client import KmsClientcorrectfrom tencentcloud.kms.v20190118 import kms_client - models
from tencentcloud.kms.v20190118 import models
Quickstart
import os
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.kms.v20190118 import kms_client, models
secret_id = os.environ.get('TENCENTCLOUD_SECRET_ID', '')
secret_key = os.environ.get('TENCENTCLOUD_SECRET_KEY', '')
if not secret_id or not secret_key:
raise ValueError('Missing credentials')
cred = credential.Credential(secret_id, secret_key)
client = kms_client.KmsClient(cred, 'ap-guangzhou')
req = models.DescribeKeysRequest()
try:
resp = client.DescribeKeys(req)
print(resp.to_json_string())
except TencentCloudSDKException as e:
print(e)