levo-commons 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {levo_commons-0.2.0 → levo_commons-0.2.2}/PKG-INFO +1 -1
- {levo_commons-0.2.0 → levo_commons-0.2.2}/setup.py +1 -1
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/request_utils.py +9 -3
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons.egg-info/PKG-INFO +1 -1
- {levo_commons-0.2.0 → levo_commons-0.2.2}/README.md +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/pyproject.toml +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/setup.cfg +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/__init__.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/config.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/cwe.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/events.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/failures.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/models.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/params.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/providers.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/status.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/types.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons/utils.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons.egg-info/SOURCES.txt +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons.egg-info/dependency_links.txt +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons.egg-info/requires.txt +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/src/levo_commons.egg-info/top_level.txt +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/test/test_config.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/test/test_request_utils.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/test/test_sanity.py +0 -0
- {levo_commons-0.2.0 → levo_commons-0.2.2}/test/test_utils.py +0 -0
|
@@ -36,14 +36,18 @@ STRING_CODE_TO_STATUS_DICT = {
|
|
|
36
36
|
|
|
37
37
|
# pylint: disable=too-many-branches
|
|
38
38
|
def get_error_code_from_response_body(
|
|
39
|
-
response: Union[Response, requests.Response]
|
|
39
|
+
response: Union[str, bytes, Response, requests.Response]
|
|
40
40
|
) -> Optional[int]:
|
|
41
41
|
"""Check if the response body contains an error code and return it.
|
|
42
42
|
|
|
43
43
|
Integer error codes take precedence over string error codes.
|
|
44
44
|
"""
|
|
45
45
|
body_str = (
|
|
46
|
-
response
|
|
46
|
+
response
|
|
47
|
+
if isinstance(response, (str, bytes))
|
|
48
|
+
else response.content
|
|
49
|
+
if isinstance(response, requests.Response)
|
|
50
|
+
else response.body
|
|
47
51
|
) or ""
|
|
48
52
|
# TODO: Be consistent about base64 encoding of response body.
|
|
49
53
|
try:
|
|
@@ -51,7 +55,9 @@ def get_error_code_from_response_body(
|
|
|
51
55
|
except Exception:
|
|
52
56
|
try:
|
|
53
57
|
decoded_body = base64.b64decode(body_str)
|
|
54
|
-
encoding =
|
|
58
|
+
encoding = "utf8"
|
|
59
|
+
if not isinstance(response, (str, bytes)) and response.encoding:
|
|
60
|
+
encoding = response.encoding
|
|
55
61
|
response_body = decoded_body.decode(encoding, errors="replace")
|
|
56
62
|
body = json.loads(response_body)
|
|
57
63
|
except Exception:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|