简体   繁体   中英

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM