This topic describes how to use Alibaba Cloud SDK for Python to call the WhiteIpList operation of Data Transmission Service (DTS).
View the API documentation
Before you call an API operation, we recommend that you read the documentation about the API operation. For more information, see List of operations by function.
Create a RAM user and grant permissions to the RAM user
If you have created a RAM user and granted permissions to the RAM user, skip this step.
Create a RAM user.
Log on to the RAM console, go to the Users page, and then click Create User.
Set the Logon Name parameter to dts-openapi-operator and select OpenAPI Access for Access Mode.
Click OK and record the AccessKey ID and AccessKey secret.
Grant permissions to the RAM user.
Go to the Users page, find the RAM user that you created, and then click Add Permissions in the Actions column.
In the panel that appears, enter
Aliyundts
in the search box and then select the AliyunDTSFullAccess policy.NoteThe AliyunDTSFullAccess policy grants the read and write permissions on DTS. If this policy is attached to a RAM user, the RAM user can purchase, configure, and manage DTS instances. The AliyunDTSReadOnlyAccess policy grants the read permissions on DTS. If this policy is attached to a RAM user, the RAM user can view the details and configurations of all DTS tasks owned by the Alibaba Cloud account. However, the RAM user cannot perform change operations.
For more information, see Use a custom policy to authorize a RAM user to manage DTS instances.
Click Grant permissions.
Call an API operation
This section describes how to use Alibaba Cloud SDK for Python to call a DTS API operation. You can use SDKs for other programming languages in a similar way. For more information, visit Data Transmission SDK.
Prepare a Python environment
Download and install Python 3. If you have installed Python, you can run the python --version
command to query its version number.
Configure environment variables
This section describes how to configure the ALIBABA_CLOUD_ACCESS_KEY_ID
and ALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables in your operating system.
If you use a Linux or macOS operating system, replace
<access_key_id>
and<access_key_secret>
in the following commands with your AccessKey ID and AccessKey secret. Then, run the commands on your device.export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
If you use a Windows operating system, create a file to add the
ALIBABA_CLOUD_ACCESS_KEY_ID
andALIBABA_CLOUD_ACCESS_KEY_SECRET
environment variables, specify your AccessKey ID and AccessKey secret by using the environment variables, and then restart the system.
Install dependencies
Run the following commands in order on your terminal device to install dependencies:
pip install alibabacloud_credentials
pip install alibabacloud_dts20200101
pip install alibabacloud_tea_console
Download the sample code
Go to the WhiteIpList page.
On the Parameters tab on the left side of the page, configure the request parameters.
In this example, specify vpc for the Type parameter, and cn-hangzhou for the Region parameter.
On the SDK Sample Code tab, select Python and click Download Project to download the sample code package.
Decompress the package and go to the alibabacloud_sample directory.
Run the code
Run the following command:
python sample.py
Sample result:
{
"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
}
}