Вызов метода API

def _call(self, method, **kwargs):
        """ Вызов метода API
        """
        kwargs.update(dict(
            partnerid=self.partner_id,
            partnerkey=self.partner_key,
            method=method,
        ))

        url = options.ENDPOINT_URL + '?' + parse.urlencode(kwargs)
        try:
            raw_json = request.urlopen(url, timeout=self.timeout).read().decode('utf-8')
            res = json.loads(raw_json)
            if 'code' in res:
                if res['code'] == 4:
                    raise InvalidCredentialsException(res['msg'])
        except (HTTPError, URLError, timeout) as e:  # ошибка запроса
            raise APIRequestException(e.__class__.__name__, e)
        except (ValueError, ) as e:  # ошибка в данных
            raise APIDataException(e.__class__.__name__, e)
        return res, raw_json