gpt4 book ai didi

python - 无法编码响应 : datetime. datetime(2019, 5, 29, 13, 41, 46, 937000, tzinfo=tzlocal()) 不是 JSON 可序列化的”,

转载 作者:行者123 更新时间:2023-12-05 07:22:50 25 4
gpt4 key购买 nike

对于 ON_DEMAND kinesis video,我正在尝试按照代码中所示的方式传递时间,但出现此错误:

"errorMessage": "Unable to marshal response: datetime.datetime(2019, 5, 29, 13, 41, 46, 937000, tzinfo=tzlocal()) is not JSON serializable",
import json
import boto3, datetime
from botocore.exceptions import ClientError

dynamodb = boto3.resource('dynamodb')

def lambda_handler(event, context):

try:


# for live video streaming getting HLS URL LIVE and ON DEMAND

live_data_end_point= boto3.client('kinesisvideo', region_name ="us-east-1").get_data_endpoint(
StreamName=event["device_name"],
APIName='GET_HLS_STREAMING_SESSION_URL'
)
live_data_end_point = live_data_end_point["DataEndpoint"]

if event["mode"]=="LIVE":
media = boto3.client('kinesis-video-archived-media',region_name = 'us-east-1', endpoint_url=live_data_end_point)
url_response = media.get_hls_streaming_session_url(

StreamName=event["device_name"],
PlaybackMode='LIVE',
DiscontinuityMode='ALWAYS',
Expires=1000,
MaxMediaPlaylistFragmentResults=123,
)

hls_url = url_response['HLSStreamingSessionURL']
hls_live_medial_url = [{'hls_url':hls_url}]
else:
media = boto3.client('kinesis-video-archived-media',region_name = 'us-east-1', endpoint_url=live_data_end_point)
url_response = media.get_hls_streaming_session_url(

StreamName=event["device_name"],
PlaybackMode='ON_DEMAND',
HLSFragmentSelector={
'FragmentSelectorType':'SERVER_TIMESTAMP',
'TimestampRange': {
'StartTimestamp':datetime.datetime(2019, 5, 29, 13, 41),
'EndTimestamp': datetime.datetime(2019, 5, 29, 13, 55)
}
},
DiscontinuityMode='ALWAYS',
Expires=1000,
MaxMediaPlaylistFragmentResults=500,
)

hls_url = url_response['HLSStreamingSessionURL']
hls_live_medial_url = [{'hls_url':hls_url}]



# for getting list of all fragments:


end_point_list_frag = boto3.client('kinesisvideo', region_name ="us-east-1").get_data_endpoint(
StreamName=event["device_name"],
APIName='LIST_FRAGMENTS'
)

end_point_list_frag = end_point_list_frag["DataEndpoint"]
client_frag = boto3.client('kinesis-video-archived-media', region_name = "us-east-1", endpoint_url = end_point_list_frag)

response = client_frag.list_fragments(
StreamName=event["device_name"],
MaxResults=123,
FragmentSelector={
'FragmentSelectorType': 'SERVER_TIMESTAMP',
'TimestampRange': {
'StartTimestamp': datetime.datetime(2019, 5, 29, 13, 41),
'EndTimestamp': datetime.datetime(2019, 5, 29, 13, 55)
}
}
)

fragments = response['Fragments']


# listing all videos available for that devices by using get_media_for_fragment_list



return {
'ResponseCode': 200,
'hls_url': hls_live_medial_url,

'fragment_list':response,

}

except ClientError as ex:
return {'Result':ex.response['Error']}

##############################################

最佳答案

使用 datetime.srtptime(datetime_object, format) 将您的日期解析为正确的格式。

关于python - 无法编码响应 : datetime. datetime(2019, 5, 29, 13, 41, 46, 937000, tzinfo=tzlocal()) 不是 JSON 可序列化的”,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56377066/

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