import inspect
import logging
import re
+
import requests
from requests.exceptions import ConnectionError, InvalidURL, Timeout
+
from .settings import Settings
from .tools import build_url
"""
Set timeout argument for all requests if this is not already done.
"""
+
def request(self, *args, **kwargs):
if ((args[8] if len(args) > 8 else None) is None) \
and kwargs.get('timeout') is None:
"{}" # TODO remove
.format(self.client_name, resp.status_code, pf(
resp.content)),
- resp.status_code,
+ self._handle_response_status_code(resp.status_code),
resp.content)
except ConnectionError as ex:
if ex.args:
logger.exception(msg)
raise RequestException(msg)
+ @staticmethod
+ def _handle_response_status_code(status_code: int) -> int:
+ """
+ Method to be overridden by subclasses that need specific handling.
+ """
+ return status_code
+
@staticmethod
def api(path, **api_kwargs):
def call_decorator(func):
def func_wrapper(self, *args, **kwargs):
method = api_kwargs.get('method', None)
resp_structure = api_kwargs.get('resp_structure', None)
- args_name = inspect.getargspec(func).args
+ args_name = inspect.getfullargspec(func).args
args_dict = dict(zip(args_name[1:], args))
- for key, val in kwargs:
+ for key, val in kwargs.items():
args_dict[key] = val
return func(
self,