[英]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'
Please let me know the correct code for this or how to deubg..请让我知道正确的代码或如何调试..
instead of using而不是使用
r = requests.post(url, params=input_json, headers=header).json()['body']
use only仅使用
r = requests.post(url, params=input_json, headers=header).json()
you are getting error coz there is no any "body" key in r...您收到错误,因为 r 中没有任何“body”键...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.