From 725e670b47df22b45f3643bb8eb0059f8ee61761 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 11 Jun 2021 13:23:41 +0200 Subject: [PATCH] [scaleway inventory] Fix JSON object must be str, not 'bytes' (#2771) (#2783) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix JSON object decoding * Code improvement : python 3.5 fix * Add changelog fragment * Update changelogs/fragments/2771-scaleway_inventory_json_accept_byte_array.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit c2ce7a0752f84d7e4ca5b373ec7a6103e3ddd6a8) Co-authored-by: Loïc --- .../2771-scaleway_inventory_json_accept_byte_array.yml | 3 +++ plugins/inventory/scaleway.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/2771-scaleway_inventory_json_accept_byte_array.yml diff --git a/changelogs/fragments/2771-scaleway_inventory_json_accept_byte_array.yml b/changelogs/fragments/2771-scaleway_inventory_json_accept_byte_array.yml new file mode 100644 index 0000000000..8a6bfd1603 --- /dev/null +++ b/changelogs/fragments/2771-scaleway_inventory_json_accept_byte_array.yml @@ -0,0 +1,3 @@ +bugfixes: + - scaleway plugin inventory - fix ``JSON object must be str, not 'bytes'`` with Python 3.5 + (https://github.com/ansible-collections/community.general/issues/2769). diff --git a/plugins/inventory/scaleway.py b/plugins/inventory/scaleway.py index ae557e2239..ad0a2321ae 100644 --- a/plugins/inventory/scaleway.py +++ b/plugins/inventory/scaleway.py @@ -89,7 +89,7 @@ from ansible.errors import AnsibleError from ansible.plugins.inventory import BaseInventoryPlugin, Constructable from ansible_collections.community.general.plugins.module_utils.scaleway import SCALEWAY_LOCATION, parse_pagination_link from ansible.module_utils.urls import open_url -from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_native, to_text import ansible.module_utils.six.moves.urllib.parse as urllib_parse @@ -105,7 +105,7 @@ def _fetch_information(token, url): except Exception as e: raise AnsibleError("Error while fetching %s: %s" % (url, to_native(e))) try: - raw_json = json.loads(response.read()) + raw_json = json.loads(to_text(response.read())) except ValueError: raise AnsibleError("Incorrect JSON payload")