JSON response 'Invalid encoding, expecting UTF-8, UTF-16 or UTF-32.' Python post process


#1

I have a simple API post-process Python script that converts the response from an invoked function to JSON from a string. The output looks great and can be parsed as expected, but I suspect the response header is not providing encoding information (or it may just be blank). Right now my script looks like this:

import json
content = event.response.content;
event.response.content = json.loads(content);
event.response.content_type = ‘application/json;charset=utf-8’;

Testing shows an error: “Invalid encoding, expecting UTF-8, UTF-16 or UTF-32.”

I have tried playing around with event.response.headers but I’ve not had any luck. Any thoughts would be appreciated. Thanks in advance.