TencentCloud SDK Python VPC
raw JSON → 3.1.82 verified Sat May 09 auth: no python
Official Tencent Cloud SDK for the Virtual Private Cloud (VPC) service. Provides a Python client for managing VPC resources such as subnets, route tables, security groups, and VPN connections. Current version 3.1.82, stable release cycle aligned with Tencent Cloud API updates.
pip install tencentcloud-sdk-python-vpc Common errors
error ImportError: cannot import name 'VpcClient' from 'tencentcloud.vpc' ↓
cause Missing API version in import path.
fix
Use: from tencentcloud.vpc.v20170312 import vpc_client
error tencentcloud.common.exception.TencentCloudSDKException: [InvalidParameter] The request is not completed as the action is not a valid API action, version: 2017-03-12, action: DescribeVpcs ↓
cause Incorrect API version or action name; often due to wrong import path.
fix
Ensure using correct version subpackage: tencentcloud.vpc.v20170312
error AttributeError: module 'tencentcloud.vpc.v20170312' has no attribute 'models' ↓
cause Missing 'models' import; need to import explicitly.
fix
Add: from tencentcloud.vpc.v20170312 import models
Warnings
breaking Migrating from SDK version <3.0 requires import path change: 'tencentcloud.vpc.v20170312' instead of 'tencentcloud.vpc' ↓
fix Update all imports to include API version in path.
breaking Model class names changed; e.g., 'DescribeVpcsRequest' instead of 'DescribeVpcsReq' ↓
fix Check API docs for current model names; use 'models.<Action>Request'.
gotcha VpcClient is not thread-safe; do not share across threads without locking. ↓
fix Create a new client per thread or use threading.Lock.
gotcha Region parameter must be set during client initialization, not per request. ↓
fix Pass region to VpcClient constructor; cannot change region per call.
deprecated Use of 'credential.DefaultCredentialProvider' deprecated in favor of explicit 'credential.Credential' ↓
fix Replace with: 'cred = credential.Credential(secret_id, secret_key)'
Install
pip install tencentcloud-sdk-python-vpc==3.1.82 Imports
- VpcClient wrong
from tencentcloud.vpc.vpc_client import VpcClientcorrectfrom tencentcloud.vpc.v20170312 import vpc_client - models wrong
from tencentcloud.vpc import modelscorrectfrom tencentcloud.vpc.v20170312 import models
Quickstart
import os
from tencentcloud.common import credential
from tencentcloud.vpc.v20170312 import vpc_client, models
try:
cred = credential.Credential(
secret_id=os.environ.get('TENCENTCLOUD_SECRET_ID', ''),
secret_key=os.environ.get('TENCENTCLOUD_SECRET_KEY', '')
)
client = vpc_client.VpcClient(cred, "ap-guangzhou")
req = models.DescribeVpcsRequest()
resp = client.DescribeVpcs(req)
print(resp)
except Exception as e:
print(f"Error: {e}")