gpt4 book ai didi

python-3.x - Boto3运动视频流:调用GetMedia操作时出错

转载 作者:行者123 更新时间:2023-12-03 17:40:34 26 4
gpt4 key购买 nike

在boto3文档下:https://boto3.readthedocs.io/en/latest/reference/services/kinesis-video-media.html#KinesisVideoMedia.Client.get_media

它说我需要先运行GetDataEndpoint API才能获取端点,然后再运行GetMedia,但是它没有说明如何向该端点提供数据?

所以我试着跑:

import boto3

kinesis_media = boto3.client('kinesis-video-media' region_name='region')

stream = kinesis_media.get_media(StreamARN='my-arn',
StartSelector={'StartSelectorType': 'EARLIEST'}) # this is not the endpoint


然后返回:

ClientError: An error occurred (403) when calling the GetMedia operation: <AccessDeniedException>
<Message>Unable to determine service/operation name to be authorized</Message>
</AccessDeniedException>


我猜是因为未指定端点,但是类型为 kinesis-video-media的客户端没有 get_data_endpoint方法,该方法需要获取端点url?

最佳答案

首先,使用kinesisvideo客户端获取端点:

import boto3

kinesis_client = boto3.client('kinesisvideo',region_name='us-west-2')

response = kinesis_client.get_data_endpoint(StreamARN='...ARN...',APIName='GET_MEDIA')


response变量包含:

{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '...', 'HTTPHeaders': {'x-amzn-requestid': '...', 'date': 'Tue, 10 Apr 2018 08:22:59 GMT', 'content-length': '74', 'content-type': 'application/json'}}, u'DataEndpoint': u'https://s-4010cf70.kinesisvideo.us-west-2.amazonaws.com'}


然后,使用给定的端点调用 kinesis-video-media客户端:

video_client = boto3.client('kinesis-video-media',endpoint_url='https://s-4010cf70.kinesisvideo.us-west-2.amazonaws.com',region_name='us-west-2')

stream = video_client.get_media(StreamARN='arn:aws:kinesisvideo:us-west-2:...',StartSelector={'StartSelectorType': 'NOW'})


stream变量包含:

{u'ContentType': 'video/webm', u'Payload': <botocore.response.StreamingBody object at 0x7f1fab294850>, 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '...', 'HTTPHeaders': {'x-amzn-requestid': '...', 'transfer-encoding': 'chunked', 'content-type': 'video/webm', 'date': 'Tue, 10 Apr 2018 08:27:19 GMT'}}}

关于python-3.x - Boto3运动视频流:调用GetMedia操作时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49746612/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com