[英]Malformed Lambda proxy response with AWS Lambda and API Gateway NodeJs
[英]AWS Lambda + API Gateway response non-utf8 CSV
要求:
问题:
response = codecs.encode(inputString, 'SHIFT_JIS', errors='ignore')
with inputString something like武蔵野冷蔵名古屋
: encode input string with shift_jisresponse
返回给用户。 但面临错误Invalid lambda response received: Invalid API Gateway Response Keys: {'requestId', 'errorMessage', 'stackTrace', 'errorType'} in {'errorMessage': "Unable to marshal response: 'utf-8' codec can't decode byte 0x95 in position 0: invalid start byte"
。似乎 API 网关只支持 UTF-8 的文本。
我关心的是在组合 Lambda + API 网关时如何响应非 UTF-8 文本。
对这个问题有帮助吗? 谢谢!
感谢上帝!
我被引导解决这个问题。
只需 base64 编码 string_after_encode_to_shift_jis。
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Origin': '*',
'Content-Type': f'application/csv; charset=shift_jis'
},
'body': base64.b64encode(data.encode(enc)).decode('utf-8'),
'isBase64Encoded': True
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.