このトピックでは、Python SDK の使用方法について説明します。 SDK を使用する際、次の手順に従います。

前提条件

Python V2.7 以降のバージョンがインストールされている必要があります。

SDK のインストール

sudo pip install aliyun-python-sdk-iot

SDK のアップグレード

sudo pip install aliyun-python-sdk-live --upgrade

SDK の削除

sudo pip uninstall aliyun-python-sdk-live

操作説明

例として DescribeLiveStreamsFrameRateAndBitRateData 操作を使用します。

SDK 内の DescribeLiveStreamsFrameRateAndBitRateDataRequest.py ファイルは次のとおりです。

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from aliyunsdkcore.request import RpcRequest
class DescribeLiveStreamsFrameRateAndBitRateDataRequest(RpcRequest):
    def __init__(self):
        RpcRequest.__init__(self, 'live', '2016-11-01', 'DescribeLiveStreamsFrameRateAndBitRateData','live')
    def get_SecurityToken(self):
        return self.get_query_params().get('SecurityToken')
    def set_SecurityToken(self,SecurityToken):
        self.add_query_param('SecurityToken',SecurityToken)
    def get_OwnerId(self):
        return self.get_query_params().get('OwnerId')
    def set_OwnerId(self,OwnerId):
        self.add_query_param('OwnerId',OwnerId)
    def get_DomainName(self):
        return self.get_query_params().get('DomainName')
    def set_DomainName(self,DomainName):
        self.add_query_param('DomainName',DomainName)
    def get_AppName(self):
        return self.get_query_params().get('AppName')
    def set_AppName(self,AppName):
        self.add_query_param('AppName',AppName)
    def get_StreamName(self):
        return self.get_query_params().get('StreamName')
    def set_StreamName(self,StreamName):
        self.add_query_param('StreamName',StreamName)
    def get_StartTime(self):
        return self.get_query_params().get('StartTime')
    def set_StartTime(self,StartTime):
        self.add_query_param('StartTime',StartTime)
    def get_EndTime(self):
        return self.get_query_params().get('EndTime')
    def set_EndTime(self,EndTime):
        self.add_query_param('EndTime',EndTime)

このファイルには、DescribeLiveStreamsFrameRateAndBitRateDataRequest クラスの get_Xset_X メソッドのペアが含まれています。 これらを使用して、操作リクエストのパラメーターを指定します。 各リクエストパラメーターの詳細については、Alibaba Cloud 公式 Web サイトの ApsaraVideo Live API ドキュメントをご参照ください。

SDK の使用

例として v20161101 バージョンを使用します。

次のセクションでは、DescribeLiveStreamsFrameRateAndBitRateDataRequest 操作を呼び出す手順を示します。
# Import the aliyunsdkcore package.
from aliyunsdkcore import client
# Import the aliyunsdklie package.
from aliyunsdklive.request.v20161101 import DescribeLiveStreamsFrameRateAndBitRateDataRequest
# Initialize the client.
# The AccessKey ID and AccessKey Secret must be provided by yourself (which can be found in the Alibaba Cloud console).
# Assume that the region to be accessed is cn-hangzhou.
clt = client.AcsClient(Your AccessKey ID, Your AccessKey Secret, 'cn-hangzhou')
# Create the operation request to be initiated.
request = DescribeLiveStreamsFrameRateAndBitRateDataRequest()
request.set_DomainName('qt1.alivecdn.com')
request.set_AppName('caster')
request.set_StreamName('cc8d5e157f5d4146afd091e246efd1f6')
# Initiate the request.
response = clt.do_action_with_exception(request)
# View the request result.
 The result is the ResponseBody string.
print rsult
 You can format the result based on the response format of each operation for further analysis or use.
# The DescribeLiveStreamsFrameRateAndBitRateDataRequest class returns data in the JSON format. We can use the JSON package to process the responses.
import json
x = json.loads(result)
print x['RequestId']
print x ['FrameRateAndBitRateInfos']