Tencent Cloud CWS SDK for Python

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

The official Tencent Cloud SDK module for the CWS (Cloud Web Scanner) service. This package is part of the larger tencentcloud-sdk-python ecosystem, version 3.0.1459. It provides Python bindings for the CWS API, enabling management of web scanning tasks, site verification, and vulnerability detection. Released irregularly alongside the main SDK.

pip install tencentcloud-sdk-python-cws
error ModuleNotFoundError: No module named 'tencentcloud.cws'
cause Missing installation of the specific submodule tencentcloud-sdk-python-cws, or mistakenly thinking it's included in the base package.
fix
Run: pip install tencentcloud-sdk-python-cws
error AttributeError: module 'tencentcloud.cws' has no attribute 'v20180312'
cause Incorrect import path; trying to import from tencentcloud.cws directly instead of the versioned subpackage.
fix
Use: from tencentcloud.cws.v20180312 import cws_client
error tencentcloud.common.exception.tencent_cloud_sdk_exception.TencentCloudSDKException: [InvalidParameter] InvalidParameter
cause Missing or invalid credentials; either SecretId or SecretKey is empty or incorrect.
fix
Set environment variables TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY properly. For temporary keys, also set TENCENTCLOUD_TOKEN.
error tencentcloud.common.exception.tencent_cloud_sdk_exception.TencentCloudSDKException: [UnauthorizedOperation] UnauthorizedOperation
cause The API key does not have permission to access CWS. Ensure the key is associated with a CAM policy granting CWS actions.
fix
Check CAM permissions in Tencent Cloud console, or use a key with full CWS access.
gotcha The module version (3.0.1459) corresponds to the SDK release, not the API version. The CWS API version is v20180312; do not confuse with the SDK version.
fix Always use 'v20180312' in the import path for the current CWS API.
breaking The Credential object no longer accepts a 'secret_key' as positional arg after version 3.0.500. Use keyword arguments or Credential(secret_id, secret_key) is still fine (both positional). However, the optional 'token' parameter changed to 'sessionToken'.
fix Use Credential(secret_id, secret_key) or Credential(secret_id, secret_key, sessionToken='...') for temporary keys.
deprecated The method 'to_json_string()' on response objects is deprecated in favor of 'to_json(indent=None)'. While still present, it may be removed.
fix Replace resp.to_json_string() with resp.to_json() or str(resp).
gotcha Region parameter in client constructor must be a valid Tencent Cloud region string (e.g., 'ap-guangzhou'). An invalid region silently defaults to 'ap-guangzhou' but may cause obscure API errors.
fix Explicitly set the region via environment variable TENCENTCLOUD_REGION or pass a known region string.
pip install tencentcloud-sdk-python-cws==3.0.1459

Lists all registered web scanning sites. Requires credentials set as environment variables TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY.

import os
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.cws.v20180312 import cws_client, models

try:
    cred = credential.Credential(
        os.environ.get('TENCENTCLOUD_SECRET_ID', ''),
        os.environ.get('TENCENTCLOUD_SECRET_KEY', '')
    )
    client = cws_client.CwsClient(cred, 'ap-guangzhou')
    req = models.DescribeSitesRequest()
    resp = client.DescribeSites(req)
    print(resp.to_json_string())
except TencentCloudSDKException as e:
    print(e)