From c6854fde29659e2fbade78ae704e1e243b0781e9 Mon Sep 17 00:00:00 2001 From: Andreas Olsson Date: Tue, 24 Jul 2018 06:21:44 +0200 Subject: [PATCH] Fix cloudflare_dns JSON response error handling (#42894) * The JSONDecodeError exception only exists in Python 3. * Without a properly parsed JSON response there is no more error processing to be done, no matter the http response code. Relates to #38178 --- lib/ansible/modules/net_tools/cloudflare_dns.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/net_tools/cloudflare_dns.py b/lib/ansible/modules/net_tools/cloudflare_dns.py index f3fcc1fffe..8a93e2afbe 100644 --- a/lib/ansible/modules/net_tools/cloudflare_dns.py +++ b/lib/ansible/modules/net_tools/cloudflare_dns.py @@ -354,11 +354,11 @@ class CloudflareAPI(object): if content: try: result = json.loads(to_text(content, errors='surrogate_or_strict')) - except (json.JSONDecodeError, UnicodeError) as e: + except (getattr(json, 'JSONDecodeError', ValueError)) as e: error_msg += "; Failed to parse API response with error {0}: {1}".format(to_native(e), content) - # received an error status but no data with details on what failed - if (info['status'] not in [200, 304]) and (result is None): + # Without a valid/parsed JSON response no more error processing can be done + if result is None: self.module.fail_json(msg=error_msg) if not result['success']: