From 1365f11402caab08f3ed6d53a47f096ec03cdbd0 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Mon, 13 Nov 2023 18:49:51 -0500 Subject: [PATCH] Fix CertificateError import in Ansible devel. (#1127) --- plugins/module_utils/api_request.py | 30 +++++++++-------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/plugins/module_utils/api_request.py b/plugins/module_utils/api_request.py index 843b64d3a..18b588e17 100644 --- a/plugins/module_utils/api_request.py +++ b/plugins/module_utils/api_request.py @@ -12,14 +12,10 @@ from uuid import uuid4 +from ssl import CertificateError from ansible.module_utils.connection import ConnectionError from ansible.module_utils.connection import Connection from ansible.module_utils._text import to_text -try: - from ansible.module_utils.urls import CertificateError - HAS_CERT_ERROR = True -except ImportError: - HAS_CERT_ERROR = False class ZabbixApiRequest(object): @@ -29,22 +25,14 @@ def __init__(self, module): self.connection = Connection(self.module._socket_path) def _httpapi_error_handle(self, payload=None): - if HAS_CERT_ERROR: - try: - code, response = self.connection.send_request(data=payload) - except ConnectionError as e: - self.module.fail_json(msg="connection error occurred: {0}".format(e)) - except CertificateError as e: - self.module.fail_json(msg="certificate error occurred: {0}".format(e)) - except ValueError as e: - self.module.fail_json(msg="certificate not found: {0}".format(e)) - else: - try: - code, response = self.connection.send_request(data=payload) - except ConnectionError as e: - self.module.fail_json(msg="connection error occurred: {0}".format(e)) - except ValueError as e: - self.module.fail_json(msg="certificate not found: {0}".format(e)) + try: + code, response = self.connection.send_request(data=payload) + except ConnectionError as e: + self.module.fail_json(msg="connection error occurred: {0}".format(e)) + except CertificateError as e: + self.module.fail_json(msg="certificate error occurred: {0}".format(e)) + except ValueError as e: + self.module.fail_json(msg="certificate not found: {0}".format(e)) if code == 404: if to_text(u"Object not found") in to_text(response) or to_text(