def check_response(self, response, success=range(200, 207), key=None):
        if isinstance(response, Response):
            if response.status_code in success:
                try:
                    r = json.loads(response.text)
                    return r if key is None else r[key]
                except:
                    _log.debug("Failed to parse response '{}' as json".format(response.text))
                    return None
            # When failed raise exception
            raise Exception("%d%s" % (response.status_code, ("\n" + response.text) if response.text else ""))
        else:
            # We have a async Future just return it
            response._calvin_key = key
            response._calvin_success = success
            self.future_responses.append(response)
            return response
dataset/ETHPy150Open EricssonResearch/calvin-base/calvin/requests/request_handler.py/RequestHandler.check_response/original