0

尝试解析 json 响应时出现以下错误

预期的字符串或缓冲区

在我的 Django 模型中,我有以下内容:

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)
        )

然后我这样称呼它

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

我知道响应是json,所以我希望这会将其更改为字典,但相反,我得到了上面的错误。

这是怎么回事?

4

1 回答 1

0

boto3文档建议get_batch_prediction返回字典而不是字符串。你不应该使用json.loads().

于 2017-02-28T15:12:43.587 回答