This topic describes how to initialize ApsaraVideo VOD SDK for Python by using an AccessKey pair or a Security Token Service (STS) token.
Prerequisites
- An Alibaba Cloud account is created. To create an Alibaba Cloud account, visit the account registration page. Real-name verification is completed. ApsaraVideo VOD is activated.
- An AccessKey pair is created to call ApsaraVideo VOD operations. You can create the AccessKey pair of your Alibaba Cloud account in the Access Key management. Alternatively, you can create a RAM user in the RAM console and grant the RAM user the permissions on ApsaraVideo VOD. For more information, see Create and grant permissions to a RAM user.
Initialization
Determine the region where you want to call ApsaraVideo VOD operations. For more information
about the supported regions, see Access regions and IDs. For example, if you want to call the operations in the China (Shanghai) region,
use cn-shanghai
.
- Use the AccessKey pair to initialize the SDK. Example:
# -*- coding: UTF-8 -*- import json import traceback from aliyunsdkcore.client import AcsClient def init_vod_client(accessKeyId, accessKeySecret): regionId = 'cn-shanghai' # The region where you want to call ApsaraVideo VOD operations. connectTimeout = 3 # Connection timeout in seconds. return AcsClient(accessKeyId, accessKeySecret, regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout)
- Use an STS token to initialize the SDK. Example:
# -*- coding: UTF-8 -*- import json import traceback from aliyunsdkcore.client import AcsClient from aliyunsdkcore.auth.credentials import StsTokenCredential def init_vod_client(accessKeyId, accessKeySecret, securityToken): regionId = 'cn-shanghai' # The region where you want to call ApsaraVideo VOD operations. connectTimeout = 3 # Connection timeout in seconds. credential = StsTokenCredential(accessKeyId, accessKeySecret, securityToken) return AcsClient(region_id=regionId, auto_retry=True, max_retry_time=3, timeout=connectTimeout, credential=credential)