Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.27.6
-------
- Only parse the response body and decode the reason in raise_for_status when an error is actually raised

1.27.5
-------
- Add PasswordProtectedArchiveError raised when a submitted archive is password protected
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.27.5'
__version__ = '1.27.6'
18 changes: 8 additions & 10 deletions intezer_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@ def raise_for_status(response: requests.Response,
statuses_to_ignore: list[HTTPStatus | int] = None,
allowed_statuses: list[HTTPStatus | int] = None):
"""Raises stored :class:`HTTPError`, if one occurred."""
try:
response_json = response.json()
except Exception:
response_json = {}

should_raise = False
http_error_msg = ''
if isinstance(response.reason, bytes):
reason = response.reason.decode('utf-8', 'ignore')
else:
reason = response.reason

if statuses_to_ignore and response.status_code in statuses_to_ignore:
return
elif allowed_statuses and response.status_code not in allowed_statuses:
should_raise = True
elif 400 <= response.status_code < 600:
try:
response_json = response.json()
except Exception:
response_json = {}
should_raise = True
if response.status_code == HTTPStatus.UNAUTHORIZED:
raise errors.InvalidApiKeyError(response)
Expand All @@ -66,6 +60,10 @@ def raise_for_status(response: requests.Response,

if should_raise:
if not http_error_msg:
if isinstance(response.reason, bytes):
reason = response.reason.decode('utf-8', 'ignore')
else:
reason = response.reason
http_error_msg = f'{response.status_code} Client Error: {reason} for url: {response.url}'
else:
http_error_msg = f'{http_error_msg}, server returns {response_json.get("error")}, details: {response_json.get("details")}'
Expand Down
Loading