Moj*_*imi 8 amazon-web-services python-3.x aws-lambda serverless-framework
我正在使用 python 3.7 在 AWS Lambda 中设置一个函数,它不会让我返回字节类型
请注意,这不是 API Gateway 的问题,我是直接调用 lambda 的。
错误是:Runtime.MarshalError, ... is not JSON serializable
output = BytesIO()
#Code that puts an excel file into output...
return {
'Content-Disposition': 'attachment; filename="export.xlsx"',
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'body' : output.getvalue()
}
Run Code Online (Sandbox Code Playgroud)
如果我做 :
'body' : str(output.getvalue())
Run Code Online (Sandbox Code Playgroud)
它输出损坏的文件,因为它添加b''到字符串
如果我做 :
'body' : base64.b64encode(output.getvalue()).decode()
Run Code Online (Sandbox Code Playgroud)
它还输出损坏的文件,可能是因为它更改了文件的二进制表示。
也许我需要上传到 S3?但它不适合我的流程,这是一次性文件创建,它会一直停留在“S3 Limbo”中,直到 TTL
| 归档时间: |
|
| 查看次数: |
1408 次 |
| 最近记录: |