【发布时间】:2020-08-22 18:33:34
【问题描述】:
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'
请告诉我正确的代码或如何调试..
【问题讨论】:
-
您确定
data发送为params而不是data吗?试试requests.post(url, data=input_json, headers=header).json()['body'],假设input_json是json编码的