This topic describes how to initialize ApsaraVideo VOD SDK for Python by using an AccessKey pair or a Security Token Service (STS) token.

Prerequisites

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.

  1. 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)
  2. 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)