Tencent Cloud Tsw SDK for Python
raw JSON → 3.0.1459 verified Sat May 09 auth: no python
Tencent Cloud Tsw (Tencent Service Weaver) SDK for Python, part of the official Tencent Cloud SDK. Version 3.0.1459. Released as part of the tencentcloud-sdk-python family; follows the same release cadence as the parent SDK.
pip install tencentcloud-sdk-python-tsw Common errors
error ModuleNotFoundError: No module named 'tencentcloud.tsw' ↓
cause The tencentcloud-sdk-python-tsw package is not installed or the import path is incorrect.
fix
Run 'pip install tencentcloud-sdk-python-tsw' and import using 'from tencentcloud.tsw.v20200924 import tsw_client'.
error AttributeError: module 'tencentcloud.tsw.v20200924' has no attribute 'TswClient' ↓
cause Direct import of class name without using the correct module (tsw_client).
fix
Use 'from tencentcloud.tsw.v20200924 import tsw_client' and then tsw_client.TswClient().
Warnings
gotcha The TswClient constructor expects a 'region' parameter; omitting it will cause silent failures or use a default region not suitable for Tsw. ↓
fix Always pass the region string, e.g., 'ap-guangzhou', to the TswClient constructor.
deprecated Older imports without version (e.g., from tencentcloud.tsw import tsw_client) are deprecated and may be removed in future releases. ↓
fix Use the full versioned import path: tencentcloud.tsw.v20200924
gotcha The API version '20200924' is the only version available; using a different version string will result in ModuleNotFoundError. ↓
fix Always use 'v20200924' when importing Tsw modules.
Imports
- TswClient wrong
from tencentcloud.tsw import TswClientcorrectfrom tencentcloud.tsw.v20200924 import tsw_client - models wrong
import modelscorrectfrom tencentcloud.tsw.v20200924 import models
Quickstart
import os
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tsw.v20200924 import tsw_client, models
try:
cred = credential.Credential(
os.environ.get('TENCENTCLOUD_SECRET_ID', ''),
os.environ.get('TENCENTCLOUD_SECRET_KEY', '')
)
client = tsw_client.TswClient(cred, 'ap-guangzhou')
req = models.DescribeComponentAlertObjectRequest()
resp = client.DescribeComponentAlertObject(req)
print(resp.to_json_string())
except TencentCloudSDKException as err:
print(err)