首页 > 解决方案 > Python 中的 Runtime.MarshalError

问题描述

我收到此错误。我正在使用 python 3.7 执行 aws lambda 函数的代码以了解 quicksight 仪表板版本。提前致谢!

errorMessage:“无法编组响应:日期时间类型的对象不是 JSON 可序列化的”,

错误类型:“Runtime.MarshalError”

代码-

import boto3
import time
import sys
client = boto3.client('quicksight')
def lambda_handler(event, context):
    response = client.list_dashboard_versions(AwsAccountId='11111', DashboardId='2222',MaxResults=10)
    return response

标签: pythonpython-3.xamazon-web-serviceserror-handlingaws-lambda

解决方案


我快速修复可能是:

import boto3
import time
import sys

import json

client = boto3.client('quicksight')

def lambda_handler(event, context):
    response = client.list_dashboard_versions(AwsAccountId='11111', DashboardId='2222',MaxResults=10)

    return json.dumps(response, default=str)

推荐阅读