[英]How to solve this keyerror?
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, params=input_json, headers=header).json()
您收到错误,因为 r 中没有任何“body”键...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.