Tencent Cloud Tbaas SDK for Python

raw JSON →
3.0.1459 verified Sat May 09 auth: no python

Official Tencent Cloud SDK for Python, specifically for the TBaaS (Tencent Blockchain as a Service) product. Current version is 3.0.1459. Released irregularly alongside other Tencent Cloud SDK packages.

pip install tencentcloud-sdk-python-tbaas
error tencentcloud.common.exception.tencent_cloud_sdk_exception.TencentCloudSDKException: [TencentCloudSDKException] code: UnauthorizedOperation, message: You are not authorized to perform this action
cause Missing or invalid SecretId/SecretKey, or the account does not have permission for TBaaS operations.
fix
Ensure TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY environment variables are set correctly, and that the account has been granted TBaaS access via CAM.
error ModuleNotFoundError: No module named 'tencentcloud'
cause Missing required common package.
fix
Run: pip install tencentcloud-sdk-python-common
error tencentcloud.common.exception.tencent_cloud_sdk_exception.TencentCloudSDKException: code: InvalidParameter, message: Parameter [ChannelId] is invalid
cause The channel name does not exist or is misspelled.
fix
Verify the exact channel ID from the TBaaS console. Note that channel names are case-sensitive.
error AttributeError: module 'tencentcloud.tbaas.v20180416' has no attribute 'tbaas_client'
cause Attempted to import from wrong path (e.g., using `from tencentcloud.tbaas import tbaas_client`).
fix
Use correct import: from tencentcloud.tbaas.v20180416 import tbaas_client
breaking The old SDK (v2.x) used a different import structure (e.g., `from tencentcloud.tbaas.v20180416 import tbaas_client` vs `from tencentcloud.tbaas.v20180416.models import ...`). In v3, model classes must be imported from `models` submodule.
fix Update imports: `from tencentcloud.tbaas.v20180416 import models` and use `models.DescribeFabricBlockRequest()`.
gotcha All API operations require a correct region parameter. TBaaS supports limited regions (e.g., ap-guangzhou, ap-beijing). Using an unsupported region will cause a 'RegionUnavailable' error.
fix Check available regions for TBaaS in Tencent Cloud documentation and specify a valid region when creating the client.
gotcha The `ChannelId` and `BlockNumber` parameters must exactly match the blockchain network configuration. For example, channel names are case-sensitive.
fix Verify the exact channel ID and block number from your TBaaS console or network config.
deprecated Some older TBaaS API actions (like `InvokeChainMakerContract`) are deprecated in favor of newer Fabric-specific methods. Using deprecated endpoints may stop working without notice.
fix Check the latest API documentation and migrate to supported actions like `DescribeFabricBlock` or `InvokeFabricContract`.
pip install tencentcloud-sdk-python-common

Initialize client with credentials and call a TBaaS API.

import os
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tbaas.v20180416 import tbaas_client, models

try:
    cred = credential.Credential(
        os.environ.get("TENCENTCLOUD_SECRET_ID", ""),
        os.environ.get("TENCENTCLOUD_SECRET_KEY", "")
    )
    client = tbaas_client.TbaasClient(cred, "ap-guangzhou")
    req = models.DescribeFabricBlockRequest()
    req.BlockNumber = 0
    req.ChannelId = "mychannel"
    resp = client.DescribeFabricBlock(req)
    print(resp.to_json_string())
except TencentCloudSDKException as err:
    print(err)