From 45e4b8f97aa8adb8222e8b83584601d3e8298ba6 Mon Sep 17 00:00:00 2001 From: pdasilva Date: Mon, 22 May 2017 12:09:51 -0700 Subject: [PATCH] Converted the response from _get_url_data using to_native (#24901) Updated the exception message to no longer use e.message. Fixes #24526 --- .../modules/web_infrastructure/jenkins_plugin.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py index 823f2f2c8c..9fe4afc107 100644 --- a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py +++ b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py @@ -330,7 +330,12 @@ class JenkinsPlugin(object): csrf_data = self._get_json_data( "%s/%s" % (self.url, "api/json"), 'CSRF') - return csrf_data["useCrumbs"] + try: + return csrf_data["useCrumbs"] + except: + self.module.fail_json( + msg="Required fields not found in the Crum response.", + details=csrf_data) def _get_json_data(self, url, what, **kwargs): # Get the JSON data @@ -338,12 +343,12 @@ class JenkinsPlugin(object): # Parse the JSON data try: - json_data = json.load(r) + json_data = json.loads(to_native(r.read())) except Exception: e = get_exception() self.module.fail_json( msg="Cannot parse %s JSON data." % what, - details=e.message) + details=to_native(e)) return json_data @@ -366,7 +371,7 @@ class JenkinsPlugin(object): self.module.fail_json(msg=msg_status, details=info['msg']) except Exception: e = get_exception() - self.module.fail_json(msg=msg_exception, details=e.message) + self.module.fail_json(msg=msg_exception, details=to_native(e)) return response