Alibaba Cloud VPC SDK for Python
raw JSON → 7.1.1 verified Fri May 01 auth: no python
Alibaba Cloud Virtual Private Cloud (VPC) SDK for Python, version 7.1.1. Provides APIs to manage VPC resources such as VPCs, vSwitches, route tables, and NAT gateways. Released frequently alongside Alibaba Cloud API updates. Requires Python >=3.7.
pip install alibabacloud-vpc20160428 Common errors
error ModuleNotFoundError: No module named 'alibabacloud_vpc20160428' ↓
cause Package not installed or wrong Python environment.
fix
Run 'pip install alibabacloud-vpc20160428' or check that you are using the correct virtual environment.
error AttributeError: module 'alibabacloud_vpc20160428' has no attribute 'Client' ↓
cause Importing Client from the package root instead of the correct submodule.
fix
Use 'from alibabacloud_vpc20160428.client import Client'
error SDK.ServerError: The specified region does not exist. ↓
cause Region ID not set in client or request.
fix
Set region_id in the Config object when creating the client, or pass it in the request parameters.
Warnings
breaking In version 7.0.0, the package name changed from 'aliyun-python-sdk-vpc' to 'alibabacloud-vpc20160428' and import paths completely changed. ↓
fix Uninstall the old package 'aliyun-python-sdk-vpc' and install 'alibabacloud-vpc20160428'. Update imports to 'alibabacloud_vpc20160428...'
deprecated The use of 'access_key_id' and 'access_key_secret' directly in client config is deprecated in favour of providing a CredentialClient instance. ↓
fix Create a CredentialClient using alibabacloud_credentials and pass to the VPC client via the 'credential' parameter.
gotcha Region ID is required for most API calls. If not set in client config, you must pass it per request. Omitting can lead to a 'region not found' error. ↓
fix Set region_id in the open_api_models.Config before creating the client, or set it in the request object.
Imports
- Client wrong
from alibabacloud_vpc20160428 import Clientcorrectfrom alibabacloud_vpc20160428.client import Client
Quickstart
import os
from alibabacloud_credentials.client import Client as CredentialClient
from alibabacloud_vpc20160428.client import Client
from alibabacloud_tea_openapi import models as open_api_models
# Setup credentials
cred_config = open_api_models.Config()
cred_config.access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
cred_config.access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
cred_client = CredentialClient(cred_config)
# Create VPC client
config = open_api_models.Config(
credential=cred_client,
# Optional: read region from env or set here
region_id=os.environ.get('ALIBABA_CLOUD_REGION_ID', 'cn-hangzhou')
)
client = Client(config)
# Example call: DescribeVpcs
from alibabacloud_vpc20160428 import models as vpc_models
request = vpc_models.DescribeVpcsRequest(
region_id=config.region_id,
page_size=10
)
response = client.describe_vpcs(request)
print(response.to_map())