diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7497afd5..12415e5348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -317,6 +317,7 @@ Ansible Changes By Release * Fix for hostname module on RHEL 7.5 (https://github.com/ansible/ansible/issues/31811) * Fix provider password leak in logs for asa modules (https://github.com/ansible/ansible/issues/32343) * Fix tagging for dynamodb_table if region is not explicitly passed to the module (https://github.com/ansible/ansible/pull/32557) +* Fix Python 3 decode error in `cloudflare_dns` (https://github.com/ansible/ansible/pull/32065) ### Known Bugs * Implicit localhost is getting ansible_connection from all:vars instead of diff --git a/lib/ansible/modules/net_tools/cloudflare_dns.py b/lib/ansible/modules/net_tools/cloudflare_dns.py index 34fbae5010..a5c9475ec8 100644 --- a/lib/ansible/modules/net_tools/cloudflare_dns.py +++ b/lib/ansible/modules/net_tools/cloudflare_dns.py @@ -274,10 +274,11 @@ import json from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode -from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_native, to_text from ansible.module_utils.urls import fetch_url + class CloudflareAPI(object): cf_api_endpoint = 'https://api.cloudflare.com/client/v4' @@ -369,9 +370,9 @@ class CloudflareAPI(object): if content: try: - result = json.loads(content) - except json.JSONDecodeError: - error_msg += "; Failed to parse API response: {0}".format(content) + result = json.loads(to_text(content, errors='surrogate_then_strict')) + except (json.JSONDecodeError, UnicodeError) 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):