尝试解析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
,所以我希望它将其更改为字典,但是,我会在上面收到错误。
发生了什么事?
boto3文档建议 get_batch_prediction
返回字典而不是字符串。您不必使用json.loads()
。