diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 6c69614..203a8ca 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -51,14 +51,15 @@ def _send_request(self, path, method="GET", data=None, params=None): response_body = {} resp, info = fetch_url(self._module, **fetch_kwargs) - if info.get("status") == 200: - try: - response_body = json.loads(resp.read().decode("utf-8")) - except (AttributeError, ValueError): - msg = "Server returned error with invalid JSON: {err}".format( - err=info.get("msg", "") - ) - return self._module.fail_json(msg=msg) + if info.get("status") in [200, 204]: + if info.get("status") == 200: + try: + response_body = json.loads(resp.read().decode("utf-8")) + except (AttributeError, ValueError): + msg = "Server returned error with invalid JSON: {err}".format( + err=info.get("msg", "") + ) + return self._module.fail_json(msg=msg) else: raise_for_error(info)