From 625876f27d8be2d9427ffa3ddf0e13ac618bf679 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Mar 2023 21:09:03 +0000 Subject: [PATCH] bump version --- rest_client/__version__.py | 2 +- rest_client/base/client.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/rest_client/__version__.py b/rest_client/__version__.py index ffcc925..156d6f9 100644 --- a/rest_client/__version__.py +++ b/rest_client/__version__.py @@ -1 +1 @@ -__version__ = '0.0.3' +__version__ = '0.0.4' diff --git a/rest_client/base/client.py b/rest_client/base/client.py index be16c31..4f1ed5f 100644 --- a/rest_client/base/client.py +++ b/rest_client/base/client.py @@ -1,5 +1,7 @@ import json +import logging import os +from json import JSONDecodeError from urllib.parse import urljoin from requests import request @@ -11,7 +13,7 @@ from rest_client.__version__ import __version__ from rest_client.base.exceptions import ApiException -log = logger_config(__name__) +log = logger_config(__name__, logging.INFO) class NoEndpointsExceptions(Exception): @@ -73,9 +75,14 @@ def _request(self, data: dict, *args, **kwargs) -> ApiResponse: self._log_response(res) + try: + response = res.json() + except JSONDecodeError: + response = res.content + if 200 <= res.status_code < 400: - return ApiResponse(res.json(), res.headers, res.status_code) - raise ApiException(res.json(), res.headers, res.status_code) + return ApiResponse(response, res.headers, res.status_code) + raise ApiException(response, res.headers, res.status_code) def _log_request(self, args, data, kwargs, request_config): log.debug('Requesting %s', (self._path(request_config.path))) @@ -89,7 +96,6 @@ def _log_response(self, res): log.debug(res.request.headers) log.debug(res.status_code) log.debug(res.headers) - log.debug(res.json()) def __getattr__(self, item): log.debug(f'Requesting endpoint: {item}')