diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d37677c..8bcbb392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ Changelog - added option to set up webhooks for actor builds - added logger with basic debugging info +### Fixed + +- disallowed `NaN` and `Infinity` values in JSONs sent to the Apify API + ### Internal changes - simplified retrying with exponential backoff diff --git a/src/apify_client/_http_client.py b/src/apify_client/_http_client.py index 71385df3..7a750292 100644 --- a/src/apify_client/_http_client.py +++ b/src/apify_client/_http_client.py @@ -96,7 +96,7 @@ def _prepare_request_call( # dump JSON data to string, so they can be gzipped if json: - data = jsonlib.dumps(json, ensure_ascii=False, default=str).encode('utf-8') + data = jsonlib.dumps(json, ensure_ascii=False, allow_nan=False, default=str).encode('utf-8') headers['Content-Type'] = 'application/json' if isinstance(data, (str, bytes, bytearray)): diff --git a/src/apify_client/_utils.py b/src/apify_client/_utils.py index 96145cc6..b69dc5e3 100644 --- a/src/apify_client/_utils.py +++ b/src/apify_client/_utils.py @@ -211,7 +211,7 @@ def _encode_key_value_store_record_value(value: Any, content_type: Optional[str] content_type = 'application/json; charset=utf-8' if 'application/json' in content_type and not _is_file_or_bytes(value) and not isinstance(value, str): - value = json.dumps(value, ensure_ascii=False, indent=2, default=str).encode('utf-8') + value = json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False, default=str).encode('utf-8') return (value, content_type)