Skip to content

Commit 64e36a9

Browse files
committed
Fixes #244
1 parent 91733b5 commit 64e36a9

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Fixed
5+
- Issue [#244](https://github.com/reportportal/client-Python/issues/244): Client crash on different error responses, by @HardNorth
46

57
## [5.5.9]
68
### Fixed

reportportal_client/core/rp_requests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"""
2020

2121
import asyncio
22-
import json as json_converter
2322
import logging
2423
from dataclasses import dataclass
2524
from typing import Callable, Optional, Union, List, Tuple, Any, TypeVar
@@ -43,6 +42,12 @@
4342
from reportportal_client.core.rp_responses import RPResponse, AsyncRPResponse
4443
from reportportal_client.helpers import dict_to_payload, await_if_necessary
4544

45+
try:
46+
# noinspection PyPackageRequirements
47+
import simplejson as json_converter
48+
except ImportError:
49+
import json as json_converter
50+
4651
logger = logging.getLogger(__name__)
4752
T = TypeVar("T")
4853

reportportal_client/core/rp_responses.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import logging
2222
from typing import Any, Optional, Generator, Mapping, Tuple, Union
2323

24-
from aiohttp import ClientResponse
24+
from aiohttp import ClientResponse, ClientError
2525
from requests import Response
2626

2727
# noinspection PyProtectedMember
@@ -41,8 +41,9 @@ def _iter_json_messages(json: Any) -> Generator[str, None, None]:
4141

4242

4343
def _get_json_decode_error_message(response: Union[Response, ClientResponse]) -> str:
44-
status = getattr(response, 'status', getattr(response, 'status_code'))
45-
return f'Unable to decode JSON response, got {"passed" if response.ok else "failed"} ' \
44+
status = getattr(response, 'status', getattr(response, 'status_code', None))
45+
ok = getattr(response, 'ok', None)
46+
return f'Unable to decode JSON response, got {"passed" if ok else "failed"} ' \
4647
f'response with code "{status}" please check your endpoint configuration or API key'
4748

4849

@@ -155,7 +156,7 @@ async def json(self) -> Any:
155156
if self.__json is NOT_SET:
156157
try:
157158
self.__json = await self._resp.json()
158-
except (ValueError, TypeError) as exc:
159+
except (ValueError, TypeError, ClientError) as exc:
159160
logger.error(_get_json_decode_error_message(self._resp), exc_info=exc)
160161
self.__json = None
161162
return self.__json

reportportal_client/helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import asyncio
1717
import inspect
18-
import json
1918
import logging
2019
import sys
2120
import threading
@@ -27,6 +26,12 @@
2726

2827
from reportportal_client.core.rp_file import RPFile
2928

29+
try:
30+
# noinspection PyPackageRequirements
31+
import simplejson as json
32+
except ImportError:
33+
import json
34+
3035
logger: logging.Logger = logging.getLogger(__name__)
3136
_T = TypeVar('_T')
3237
ATTRIBUTE_LENGTH_LIMIT: int = 128

0 commit comments

Comments
 (0)