我使用 python 3.6,我想使用 API 将视频流发布到 aws kinesis。
我使用 python aws 客户端创建流并GetDataEndPoint
但是当我想用我的自定义请求发布我的数据时(PutMedia
实际上不包含在 python 客户端中),我收到错误Unable to determine service/operation name to be authorized
.
我遵循了 aws kinesis video media 的 api 文档PutMedia https://docs.aws.amazon.com/fr_fr/kinesisvideostreams/latest/dg/API_dataplane_PutMedia.html#API_dataplane_PutMedia_Errors and GetMedia https://docs.aws.amazon.com/fr_fr/kinesisvideostreams/latest/dg/API_dataplane_GetMedia.html.
所以我首先获取端点GetDataEndPoint
with 客户端方法 http://boto3.readthedocs.io/en/latest/reference/services/kinesisvideo.html#KinesisVideo.Client.get_data_endpoint:
response = client.get_data_endpoint( # aws client method
StreamName=STREAM_NAME,
APIName='PUT_MEDIA'
)
end_point = response['DataEndpoint'] # https://s-EXAMPLE.kinesisvideo.eu-west-1.amazonaws.com
我在这个网址发布我的数据:
headers = {
"x-amzn-stream-arn": STREAM_ARN,
"x-amzn-fragment-timecode-type": "ABSOLUTE",
"x-amzn-producer-start-timestamp": start_tmstp
}
# Sign header...
response = requests.post(end_point, data=data, headers=headers) # 403 - Unable to determine service/operation name to be authorized
所以我不明白为什么我会收到这个错误......我发现了这个故障排除 https://docs.aws.amazon.com/fr_fr/kinesisvideostreams/latest/dg/troubleshooting.html#troubleshooting-api-name-auth在 aws 文档上。但他们说我们必须指定 ApiName 参数。我做什么...
如果未正确指定端点,则可能会发生此错误。当您获取端点时,请务必在 GetDataEndpoint 调用中包含以下参数,具体取决于要调用的 API:
我也想知道是否GetMedia
正如他们所说,方法实际上是在客户端实现的here https://boto3.readthedocs.io/en/latest/reference/services/kinesis-video-media.html#KinesisVideoMedia.Client.get_media因为当我调试这个方法时,客户端不会调用GetDataEndPoint
所以提出请求https://kinesisvideo.region.amazonaws.com
代替https://ID_EXAMPLE.kinesisvideo.region.amazonaws.com
。所以方法得到错误Unable to determine service/operation name to be authorized
如中所解释的故障排除 https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/troubleshooting.html#troubleshooting-api-name-auth