From c4b1f061f1bf9ff0fabc5a6c7d8544d90173a6a9 Mon Sep 17 00:00:00 2001 From: Alejandro de Alda Date: Mon, 11 Nov 2024 15:27:18 +0100 Subject: [PATCH] Fix sanity issues --- plugins/httpapi/nd.py | 2 +- plugins/module_utils/ndi.py | 4 +++- plugins/modules/nd_pcv.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/httpapi/nd.py b/plugins/httpapi/nd.py index de30e5a..d5352e2 100644 --- a/plugins/httpapi/nd.py +++ b/plugins/httpapi/nd.py @@ -255,7 +255,7 @@ def send_file_request(self, method, path, file=None, data=None, remote_path=None self.method = "GET" if method is not None: self.method = method - + # If file_ext is provided, replace the file extension (if present) or add it if file_ext is not None: if not file_ext.startswith(".") or file_ext not in set(mimetypes.types_map.keys()): diff --git a/plugins/module_utils/ndi.py b/plugins/module_utils/ndi.py index 41a993b..2e1327a 100644 --- a/plugins/module_utils/ndi.py +++ b/plugins/module_utils/ndi.py @@ -8,7 +8,6 @@ from __future__ import absolute_import, division, print_function import json -from lxml import etree try: from jsonpath_ng import parse @@ -310,7 +309,10 @@ def is_json(self, myjson): def is_xml(self, myxml): try: + from lxml import etree etree.parse(myxml) + except ImportError: + self.nd.fail_json(msg="Cannot use lxml etree because lxml module is not available") except etree.XMLSyntaxError: return False return True diff --git a/plugins/modules/nd_pcv.py b/plugins/modules/nd_pcv.py index ccd99de..8da95ed 100644 --- a/plugins/modules/nd_pcv.py +++ b/plugins/modules/nd_pcv.py @@ -227,7 +227,7 @@ def main(): try: file_ext = ".json" extract_data = ndi.load(open(file)) - except: + except BaseException: nd.fail_json(msg="Error processing the file. Check if file content is valid.") if isinstance(extract_data, list):