Requirement:
Issue:
response = codecs.encode(inputString, 'SHIFT_JIS', errors='ignore')
with inputString something like 武蔵野冷蔵名古屋
: encode input string with shift_jisresponse
to user. But facing error 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"
.Seem that API Gateway just support UTF-8 for text.
My concern is how to response non UTF-8 text when combine Lambda + API Gateway.
Any help for this issue? Thanks!
Thank God!
I was guided to solve this issue.
Just base64 encode the 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
}