Tencent Cloud CDN SDK for Python
raw JSON → 3.1.89 verified Sat May 09 auth: no python
Official Tencent Cloud SDK for the Content Delivery Network (CDN) service. Version 3.1.89. Monthly release cadence closely following the SDK generator.
pip install tencentcloud-sdk-python-cdn Common errors
error ModuleNotFoundError: No module named 'tencentcloud' ↓
cause Missing base tencentcloud-sdk-python package or the specific CDN package.
fix
Run 'pip install tencentcloud-sdk-python-cdn'. This installs the common dependency automatically.
error AttributeError: module 'tencentcloud' has no attribute 'cdn' ↓
cause Attempting to import from 'tencentcloud.cdn' directly without specifying versioned module.
fix
Use the correct import: from tencentcloud.cdn.v20180606 import cdn_client
error tencentcloud.common.exception.TencentCloudSDKException: Failed to parse SSEResponse ↓
cause Incorrect request parameters or malformed JSON. Often due to missing required fields like 'Domain' or wrong date format.
fix
Verify request model fields using the API documentation. Use the correct model class from models module.
Warnings
breaking In version 3.0.x and earlier, SDK was installed as a monolithic 'tencentcloud-sdk-python' package. Now each service is a separate package. Ensure you install the correct specific package for CDN. ↓
fix Uninstall the old package (pip uninstall tencentcloud-sdk-python) and install per-service package: pip install tencentcloud-sdk-python-cdn.
gotcha The client constructor requires a region (e.g., 'ap-guangzhou') as second argument, even for global services like CDN. Using an empty string may lead to unexpected behavior. ↓
fix Always specify a valid region string, typically 'ap-guangzhou' for CDN.
deprecated The older authentication method using SecretId/SecretKey directly in code is discouraged. Use environment variables or Tencent Cloud CAM roles. ↓
fix Use Credential constructor with environment variables or assume-role.
Imports
- CdnClient wrong
from tencentcloud.cdn import CdnClientcorrectfrom tencentcloud.cdn.v20180606 import cdn_client
Quickstart
import os
from tencentcloud.common import credential
from tencentcloud.cdn.v20180606 import cdn_client, models
cred = credential.Credential(
os.environ.get('TENCENTCLOUD_SECRET_ID', ''),
os.environ.get('TENCENTCLOUD_SECRET_KEY', '')
)
client = cdn_client.CdnClient(cred, "ap-guangzhou")
req = models.DescribeCdnDataRequest()
req.Metric = "flux"
req.Domain = "example.com"
req.StartTime = "2023-01-01 00:00:00"
req.EndTime = "2023-01-02 00:00:00"
resp = client.DescribeCdnData(req)
print(resp)