Python SDK example
Use the Alibaba Cloud SDK for Python to call the WhiteIpList API operation to query the IP addresses of Data Transmission Service (DTS).
Review the API documentation
Before you call an API operation, review its parameters and permission requirements. For more information, see API overview.
Create a RAM user and grant permissions
If you have already created a RAM user and granted the required permissions, you can skip this step.
-
Create a RAM user:
-
Go to the Users page and click Create User.
-
Set Logon name to dts-openapi-operator and Access mode to Programmatic Access.
-
Click OK, and then save the AccessKey ID and AccessKey secret.
-
-
Grant permissions:
-
Go to the Users page. In the Operation column for the target RAM user, click Add Permissions.
-
Under Permission policy, search for
Aliyundtsin the text box and select the AliyunDTSFullAccess policy.Note-
The AliyunDTSFullAccess policy grants full read and write permissions to purchase, configure, and manage DTS instances. The AliyunDTSReadOnlyAccess policy grants read-only permissions to view all DTS task details and configurations but not make changes.
-
You can also create a custom policy. For more information, see DTS custom permission policy reference.
-
-
Click OK.
-
Call an API operation
The following example uses the Alibaba Cloud SDK for Python. The process is similar for SDKs in other languages. For more information, see Data Transmission Service (DTS) SDK.
Prepare the Python environment
Download and install Python 3. If you have Python installed, you can check its version by running python --version.
Configure environment variables
Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
-
For Linux and macOS: Replace
<access_key_id>and<access_key_secret>with your AccessKey ID and AccessKey secret. Then, run the following commands in your terminal.export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret> -
For Windows: Create an environment variable file. Add the
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables and set their values to your AccessKey ID and AccessKey secret. Then, restart Windows.
Install dependencies
Run the following commands to install the required dependencies.
pip install alibabacloud_credentials
pip install alibabacloud_dts20200101
pip install alibabacloud_tea_console
Download the sample code
-
Go to the WhiteIpList API debugging page on OpenAPI Portal.
-
On the Parameters tab on the left, configure the required parameters.
For this example, enter vpc for the Type parameter and cn-hangzhou for the Region parameter.
-
On the SDK Sample tab on the right, select Python and click Download Project.
-
Extract the downloaded package and navigate to the alibabacloud_sample directory.
Run the code
Run the following command.
python sample.py
Sample response:
{
"headers": {
"date": "Wed, 26 Jul 2023 01:38:10 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "2349",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"vary": "Accept-Encoding",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "F67A05B4-639B-5A3E-800F-2015E31D****",
"x-acs-trace-id": "cd5216b8e3d13a155510760d6b7f****",
"etag": "2iMUqZd0YJhWwB0iy0qP****"
},
"statusCode": 200,
"body": {
"HttpStatusCode": 200,
"IpList": "100.104.XX.XX/XX,100.104.XX.XX/XX,100.104.XX.XX/XX,****",
"RequestId": "F67A05B4-639B-5A3E-800F-2015E31D****",
"Success": true
}
}