Get `result` field from Betfair response or raise exception if not
    found.

    :param Response response:
    :raises: ApiError if no results passed
967885
def result_or_error(response):
    
    data = response.json()
    result = data.get('result')
    if result is not None:
        return result
    raise exceptions.ApiError(response, data)
583393
def _parse_response(response, post_request=False):
        
        try:
            data = response.json()
        except:
            msg = 'Unhandled HTTP %s response, shown truncated below:\n%s...' % (
                response.status_code, response.text[:50]
            )
            raise ValueError(msg)

        if not response.ok:
            utils.error_message_and_exit(None, data)

        if post_request and not data['success']:
            raise Exception('Asmaster Api Error: [%s]' % data['error'])

        return data
1146983
def _raise_or_extract(self, response):
        

        try:
            data = response.json()
        except ValueError:
            raise JoeException("The server responded with an unexpected format ({}). Is the API url correct?". format(response.status_code))

        try:
            if response.ok:
                return data['data']
            else:
                error = data['errors'][0]
                raise ApiError(error)
        except (KeyError, TypeError):
            raise JoeException("Unexpected data ({}). Is the API url correct?". format(response.status_code))
1285390
def _check_response(response, expected):
        

        response_code = response.status_code
        if expected == response_code:
            return

        if response_code < 400:
            raise ex.UnexpectedResponseCodeException(response.text)

        elif response_code == 401:
            raise ex.UnauthorizedException(response.text)

        elif response_code == 400:
            raise ex.BadRequestException(response.text)

        elif response_code == 403:
            raise ex.ForbiddenException(response.text)

        elif response_code == 404:
            raise ex.NotFoundException(response.text)

        elif response_code == 429:
            raise ex.RateLimitedException(response.text)

        else:
            raise ex.InternalServerErrorException(response.text)
593662
def get_json_results(self, response):
        '''
        
        '''
        try:
            # return the proper JSON object, or error code if request didn't go through.
            self.most_recent_json = response.json()
            json_results = response.json()
            if response.status_code in [401, 403]: #401 is invalid key, 403 is out of monthly quota.
                raise PyMsCognitiveWebSearchException("CODE {code}: {message}".format(code=response.status_code,message=json_results["message"]) )
            elif response.status_code in [429]: #429 means try again in x seconds.
                message = json_results['message']
                try:
                    # extract time out seconds from response
                    timeout = int(re.search('in (.+?) seconds', message).group(1)) + 1
                    print ("CODE 429, sleeping for {timeout} seconds").format(timeout=str(timeout))
                    time.sleep(timeout)
                except (AttributeError, ValueError) as e:
                    if not self.silent_fail:
                        raise PyMsCognitiveWebSearchException("CODE 429. Failed to auto-sleep: {message}".format(code=response.status_code,message=json_results["message"]) )
                    else:
                        print ("CODE 429. Failed to auto-sleep: {message}. Trying again in 5 seconds.".format(code=response.status_code,message=json_results["message"]))
                        time.sleep(5)
        except ValueError as vE:
            if not self.silent_fail:
                raise PyMsCognitiveWebSearchException("Request returned with code %s, error msg: %s" % (r.status_code, r.text))
            else:
                print ("[ERROR] Request returned with code %s, error msg: %s. \nContinuing in 5 seconds." % (r.status_code, r.text))
                time.sleep(5)
        return json_results
133450
protected static UNode getUNodeResult(RESTResponse response) {
        return UNode.parse(response.getBody(), response.getContentType());
    }
452817
def get_response(self):
        
        res = ARBlockRes()
        for field in ["ARType", "ARUUID", "SessionKey"]:
            res.setfieldval(field, self.getfieldval(field))
        return res
415469
def from_response_data(cls, response_data):
        

        response_json = response_data.json()

        return cls(
            response_data.url,
            response_json["number_of_page_results"],
            response_json["number_of_total_results"],
            response_json["results"],
        )
972712
def _handle_response(response):
        

        if not str(response.status_code).startswith('2'):
            raise KucoinAPIException(response)
        try:
            res = response.json()

            if 'code' in res and res['code'] != "200000":
                raise KucoinAPIException(response)

            if 'success' in res and not res['success']:
                raise KucoinAPIException(response)

            # by default return full response
            # if it's a normal response we have a data attribute, return that
            if 'data' in res:
                res = res['data']
            return res
        except ValueError:
            raise KucoinRequestException('Invalid Response: %s' % response.text)
59389
def _gen_result_handler(self):
        
        while True:
            try:
                data = self._client.read_until(self.SEPARATOR)
            except:
                raise
            else:
                response = self.decoder(data)
                code = response.get("CODE")
                res = response.get("MESSAGE")
                if code == 202:
                    result = res.get('RESULT')
                    yield result
                if code == 206:
                    break
794084
def _loads(self, response):
        
        return bser.loads(
            response,
            True,
            value_encoding=encoding.get_local_encoding(),
            value_errors=encoding.default_local_errors,
        )
659655
def evaluate_response(json_response):
        """"""
        if 'errors' in json_response and json_response['errors']:
            Interface.evaluate_errors(json_response)
        elif 'result' not in json_response:
            raise PyVLXException('no element result  found in response: {0}'.format(json.dumps(json_response)))
        elif not json_response['result']:
            raise PyVLXException('Request failed {0}'.format(json.dumps(json_response)))
193960
def _handle_result_by_key(self, key):
        
        invalid_options = ('key', 'keys', 'startkey', 'endkey')
        if any(x in invalid_options for x in self.options):
            raise ResultException(102, invalid_options, self.options)
        return self._ref(key=key, **self.options)
538159
def getResult(self, queue, uid, suid=None):
        
        if suid:
            r = self._get_client().get('rhumba.dq.%s.%s.%s' % (suid, queue, uid))
        else:
            r = self._get_client().get('rhumba.q.%s.%s' % (queue, uid))

        if r:
            return json.loads(r)
        else:
            return None
127937
def _assert_response_success(self, response):
        

        if response.status_code != self._STATUS_CODE_OK:
            raise ExceptionFactory.create_exception_for_response(
                response.status_code,
                self._fetch_all_error_message(response),
                self._fetch_response_id(response)
            )
123727
def result(self, result):
        
        if result and len(result[2]) > 0:
            self.errs.extend([((result[0], result[1]), err) for err in result[2]])
1103677
def read_response(self):
        
        try:
            response = self._parser.read_response()
        except:
            self.disconnect()
            raise
        if isinstance(response, ResponseError):
            raise response
        #print(response)
        return response