0

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(
        BatchPredictionId=str(self.id)
        )

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 json so I expected this to change it to a dictionary but, instead, I get the error above.

What's going on?

HenryM
  • 5,557
  • 7
  • 49
  • 105

1 Answers1

0

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

Alasdair
  • 298,606
  • 55
  • 578
  • 516