视频直播 LIVE-Python SDK使用指导:代码示例

时间:2024-07-02 19:12:59

代码示例

调用前请根据实际情况替换如下变量:{your endpoint string} 以及 {your project id}。

认证用的AK、SK直接写入代码,会有很大安全风险,建议密文形式存放在配置文件或者环境变量中,待使用时再解密,以确保安全。

本示例以AK、SK保存在环境变量中为例。运行本示例前,请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcore.http.http_config import HttpConfig
from huaweicloudsdklive.v1 import *

def show_transcodings_template(client):
    try:
        request = huaweicloudsdklive.ShowTranscodingsTemplateRequest("play.example.huaweicloud.com")
        response = client.show_transcodings_template(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

if __name__ == "__main__":
    ak = os.environ["HUAWEICLOUD_SDK_AK"]
    sk = os.environ["HUAWEICLOUD_SDK_SK"]
    endpoint = "{your endpoint}"
    project_id = "{your project id}"

    config = HttpConfig.get_default_config()
    config.ignore_ssl_verification = True
    credentials = BasicCredentials(ak, sk, project_id)

    live_client = LiveAPIClient.new_builder(LiveAPIClient) \
        .with_http_config(config) \
        .with_credentials(credentials) \
        .with_endpoint(endpoint) \
        .build()

    show_transcodings_template(live_client)
support.huaweicloud.com/ssdk-live/live_18_0003.html