Skip to content

Commit f1c69f2

Browse files
authored
Fix encoding webhook lists in request parameters (#126)
Webhooks could not be parsed on the API when sent base64-encoded as bytes, they need to be sent as string.
1 parent 1c4b24b commit f1c69f2

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
[1.2.2](../../releases/tag/v1.2.2) - 2023-05-31
5+
6+
### Fixed
7+
8+
- Fixed encoding webhook lists in request parameters
9+
410
[1.2.1](../../releases/tag/v1.2.1) - 2023-05-23
511

612
### Fixed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "apify_client"
3-
version = "1.2.1"
3+
version = "1.2.2"
44
description = "Apify API client for Python"
55
readme = "README.md"
66
license = {text = "Apache Software License"}

src/apify_client/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _catch_not_found_or_throw(exc: 'ApifyApiError') -> None:
169169
return None
170170

171171

172-
def _encode_webhook_list_to_base64(webhooks: List[Dict]) -> bytes:
172+
def _encode_webhook_list_to_base64(webhooks: List[Dict]) -> str:
173173
"""Encode a list of dictionaries representing webhooks to their base64-encoded representation for the API."""
174174
data = []
175175
for webhook in webhooks:
@@ -181,7 +181,7 @@ def _encode_webhook_list_to_base64(webhooks: List[Dict]) -> bytes:
181181
webhook_representation['payloadTemplate'] = webhook['payload_template']
182182
data.append(webhook_representation)
183183

184-
return base64.b64encode(json.dumps(data).encode('utf-8'))
184+
return base64.b64encode(json.dumps(data).encode('utf-8')).decode('ascii')
185185

186186

187187
def _filter_out_none_values_recursively(dictionary: Dict) -> Dict:

tests/unit/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async def bails_on_third_attempt(stop_retrying: Callable, attempt: int) -> Any:
213213

214214

215215
def test__encode_webhook_list_to_base64() -> None:
216-
assert _encode_webhook_list_to_base64([]) == b'W10='
216+
assert _encode_webhook_list_to_base64([]) == 'W10='
217217
assert _encode_webhook_list_to_base64([
218218
{
219219
'event_types': [WebhookEventType.ACTOR_RUN_CREATED],
@@ -224,7 +224,7 @@ def test__encode_webhook_list_to_base64() -> None:
224224
'request_url': 'https://example.com/run-succeeded',
225225
'payload_template': '{"hello": "world", "resource":{{resource}}}',
226226
},
227-
]) == b'W3siZXZlbnRUeXBlcyI6IFsiQUNUT1IuUlVOLkNSRUFURUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tY3JlYXRlZCJ9LCB7ImV2ZW50VHlwZXMiOiBbIkFDVE9SLlJVTi5TVUNDRUVERUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tc3VjY2VlZGVkIiwgInBheWxvYWRUZW1wbGF0ZSI6ICJ7XCJoZWxsb1wiOiBcIndvcmxkXCIsIFwicmVzb3VyY2VcIjp7e3Jlc291cmNlfX19In1d' # noqa: E501
227+
]) == 'W3siZXZlbnRUeXBlcyI6IFsiQUNUT1IuUlVOLkNSRUFURUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tY3JlYXRlZCJ9LCB7ImV2ZW50VHlwZXMiOiBbIkFDVE9SLlJVTi5TVUNDRUVERUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tc3VjY2VlZGVkIiwgInBheWxvYWRUZW1wbGF0ZSI6ICJ7XCJoZWxsb1wiOiBcIndvcmxkXCIsIFwicmVzb3VyY2VcIjp7e3Jlc291cmNlfX19In1d' # noqa: E501
228228

229229

230230
def test__maybe_extract_enum_member_value() -> None:

0 commit comments

Comments
 (0)