def _request(self, method, uri, path_params=None, **kwargs): if path_params: # Ensure path param is encoded. path_params = { key: quote(str(value), safe=u'') for key, value in path_params.items() } uri %= path_params full_uri = self._endpoint + uri logging.debug(u'API Request: %s %s %s' % (method, full_uri, kwargs)) response = requests.request(method, full_uri, headers=self._headers, **kwargs) log_message = u'API Response: %s %s %s %s %s %s' % ( response.request.method, response.url, response.reason, ('status_code', response.status_code), response.headers.get('x-gateway-site-id'), response.headers.get('x-request-uuid')) logging.debug(log_message) if not 200 <= response.status_code <= 299: logging.error(log_message) return response
def _request(self, method, uri, path_params=None, flatten_params=True, **kwargs): if path_params: # Ensure path param is encoded. path_params = { key: quote(str(value), safe=u'') for key, value in path_params.items() } uri %= path_params # Custom nested object flattening if flatten_params and 'params' in kwargs: kwargs['params'] = self._flatten_param(kwargs['params']) full_uri = self._endpoint + uri response = self._session.request(method, full_uri, **kwargs) log_message = format_request(response) logging.info(log_message) if not 200 <= response.status_code <= 299: logging.error(log_message) return response
def _request(self, method, uri, path_params=None, **kwargs): if path_params: # Ensure path param is encoded. path_params = {key: quote(str(value), safe=u'') for key, value in path_params.items()} uri %= path_params full_uri = self._endpoint + uri response = requests.request(method, full_uri, headers=self._headers, **kwargs) log_message = format_request(response) logging.info(log_message) if not 200 <= response.status_code <= 299: logging.error(log_message) return response