如何解决如何解决这个关键错误?
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”键...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。