Python 如何解决这个关键错误?
请告诉我正确的代码或如何使用deubg..而不是使用Python 如何解决这个关键错误?,python,json,keyerror,Python,Json,Keyerror,请告诉我正确的代码或如何使用deubg..而不是使用 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
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中没有任何“body”键,因此出现错误。您确定
数据
将作为参数发送,而不是数据
?尝试requests.post(url,data=input\u json,headers=header).json()['body']
,假设input\u json
是json编码的
r = requests.post(url, params=input_json, headers=header).json()