HenryM HenryM -4 years ago 272
JSON Question

Unable to use json.loads on boto3.client.get_batch_predictions()

I'm getting the following error when trying to parse a json response

expected string or buffer

Within my Django model I have the following:

def get_batch_prediction(self):
client = boto3.client('machinelearning', region_name=settings.region, aws_access_key_id=settings.aws_access_key_id, aws_secret_access_key=settings.aws_secret_access_key)
return client.get_batch_prediction(

I then call it like so

batch = BatchPrediction.objects.get(id=batch_id)
response = batch.get_batch_prediction()
response = json.loads(response)

I know the response is
so I expected this to change it to a dictionary but, instead, I get the error above.

What's going on?

Answer Source

The boto3 docs suggest that get_batch_prediction returns a dictionary not a string. You shouldn't have to use json.loads().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download