问题描述
header = {'Content-Type': 'application/x-www-form-urlencoded'}
url = 'https://tk9k0fkvyj.execute-api.us-east-2.amazonaws.com/default/top20-predictor'
# make POST request and load response
r = requests.post(url,params=input_json,headers=header).json()['body']
result = json.loads(r)
# render the html template sending the variables
return render_template("score.html",score=result['score'],proba=result['proba'])
KeyError: 'body'
请告知我正确的代码或如何调试。
解决方法
代替使用
r = requests.post(url,params=input_json,headers=header).json()['body']
仅使用
r = requests.post(url,headers=header).json()
您收到错误提示,因为r中没有任何“ body”键...