Skip to content

Commit

Permalink
Fix encoding webhook lists in request parameters (#126)
Browse files Browse the repository at this point in the history
Webhooks could not be parsed on the API when sent base64-encoded as
bytes, they need to be sent as string.
  • Loading branch information
fnesveda authored May 31, 2023
1 parent 1c4b24b commit f1c69f2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

[1.2.2](../../releases/tag/v1.2.2) - 2023-05-31

### Fixed

- Fixed encoding webhook lists in request parameters

[1.2.1](../../releases/tag/v1.2.1) - 2023-05-23

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "apify_client"
version = "1.2.1"
version = "1.2.2"
description = "Apify API client for Python"
readme = "README.md"
license = {text = "Apache Software License"}
Expand Down
4 changes: 2 additions & 2 deletions src/apify_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _catch_not_found_or_throw(exc: 'ApifyApiError') -> None:
return None


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

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


def _filter_out_none_values_recursively(dictionary: Dict) -> Dict:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def bails_on_third_attempt(stop_retrying: Callable, attempt: int) -> Any:


def test__encode_webhook_list_to_base64() -> None:
assert _encode_webhook_list_to_base64([]) == b'W10='
assert _encode_webhook_list_to_base64([]) == 'W10='
assert _encode_webhook_list_to_base64([
{
'event_types': [WebhookEventType.ACTOR_RUN_CREATED],
Expand All @@ -224,7 +224,7 @@ def test__encode_webhook_list_to_base64() -> None:
'request_url': 'https://example.com/run-succeeded',
'payload_template': '{"hello": "world", "resource":{{resource}}}',
},
]) == b'W3siZXZlbnRUeXBlcyI6IFsiQUNUT1IuUlVOLkNSRUFURUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tY3JlYXRlZCJ9LCB7ImV2ZW50VHlwZXMiOiBbIkFDVE9SLlJVTi5TVUNDRUVERUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tc3VjY2VlZGVkIiwgInBheWxvYWRUZW1wbGF0ZSI6ICJ7XCJoZWxsb1wiOiBcIndvcmxkXCIsIFwicmVzb3VyY2VcIjp7e3Jlc291cmNlfX19In1d' # noqa: E501
]) == 'W3siZXZlbnRUeXBlcyI6IFsiQUNUT1IuUlVOLkNSRUFURUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tY3JlYXRlZCJ9LCB7ImV2ZW50VHlwZXMiOiBbIkFDVE9SLlJVTi5TVUNDRUVERUQiXSwgInJlcXVlc3RVcmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9ydW4tc3VjY2VlZGVkIiwgInBheWxvYWRUZW1wbGF0ZSI6ICJ7XCJoZWxsb1wiOiBcIndvcmxkXCIsIFwicmVzb3VyY2VcIjp7e3Jlc291cmNlfX19In1d' # noqa: E501


def test__maybe_extract_enum_member_value() -> None:
Expand Down

0 comments on commit f1c69f2

Please sign in to comment.