From 89d82ab9dfe9eb5ecda7a47a11f10a7b4f4d6d7f Mon Sep 17 00:00:00 2001 From: RealCharlesChia <161665317+RealCharlesChia@users.noreply.github.com> Date: Tue, 28 Apr 2026 02:44:52 +0800 Subject: [PATCH] scaleway: fix NoneType error in get_resources() (#11918) * scaleway: fix NoneType error in get_resources() when API returns empty or non-JSON response * add changelog fragment for #11918 * Update changelogs/fragments/11361-scaleway-get-resources-none-type.yml Co-authored-by: Felix Fontein --------- Co-authored-by: RealCharlesChia Co-authored-by: Felix Fontein --- .../fragments/11361-scaleway-get-resources-none-type.yml | 2 ++ plugins/module_utils/_scaleway.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/11361-scaleway-get-resources-none-type.yml diff --git a/changelogs/fragments/11361-scaleway-get-resources-none-type.yml b/changelogs/fragments/11361-scaleway-get-resources-none-type.yml new file mode 100644 index 0000000000..b12d37deaa --- /dev/null +++ b/changelogs/fragments/11361-scaleway-get-resources-none-type.yml @@ -0,0 +1,2 @@ +bugfixes: + - scaleway_image_info, scaleway_ip_info, scaleway_organization_info, scaleway_security_group_info, scaleway_server_info, scaleway_snapshot_info, scaleway_volume_info - fix ``NoneType`` error when the Scaleway API returns an empty or non-JSON response body (https://github.com/ansible-collections/community.general/issues/11361, https://github.com/ansible-collections/community.general/pull/11918). \ No newline at end of file diff --git a/plugins/module_utils/_scaleway.py b/plugins/module_utils/_scaleway.py index 05b45481ef..9fe744d624 100644 --- a/plugins/module_utils/_scaleway.py +++ b/plugins/module_utils/_scaleway.py @@ -240,10 +240,15 @@ class Scaleway: results = self.get(f"/{self.name}") if not results.ok: + api_response = results.json if results.json is not None else results.body + message = api_response.get("message") if isinstance(api_response, dict) else api_response raise ScalewayException( - f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {results.json['message']}]" + f"Error fetching {self.name} ({self.module.params.get('api_url')}/{self.name}) [{results.status_code}: {message}]" ) + if results.json is None: + raise ScalewayException(f"Scaleway API returned an empty or non-JSON response for {self.name}") + return results.json.get(self.name) def _url_builder(self, path, params):