[英]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.