From 4180882fb741f6ba4fb5b47590a3518fbd005fb2 Mon Sep 17 00:00:00 2001 From: Steffen Schwebel Date: Fri, 21 May 2021 15:10:17 +0200 Subject: [PATCH 1/3] show traceback --- powerdnsadmin/lib/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerdnsadmin/lib/utils.py b/powerdnsadmin/lib/utils.py index d7f20a4..2aa4d22 100644 --- a/powerdnsadmin/lib/utils.py +++ b/powerdnsadmin/lib/utils.py @@ -4,6 +4,7 @@ import json import requests import hashlib import ipaddress +import traceback from collections.abc import Iterable from distutils.version import StrictVersion @@ -105,6 +106,7 @@ def fetch_json(remote_url, try: data = json.loads(r.content.decode('utf-8')) except Exception as e: + traceback.print_exc() raise RuntimeError( 'Error while loading JSON data from {0}'.format(remote_url)) from e return data From d23a57da506b203963294563e79bc2dc04165b8a Mon Sep 17 00:00:00 2001 From: Steffen Schwebel Date: Tue, 25 May 2021 12:35:53 +0200 Subject: [PATCH 2/3] handle decode error, output warning --- powerdnsadmin/lib/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/powerdnsadmin/lib/utils.py b/powerdnsadmin/lib/utils.py index 2aa4d22..6caa88c 100644 --- a/powerdnsadmin/lib/utils.py +++ b/powerdnsadmin/lib/utils.py @@ -105,6 +105,13 @@ def fetch_json(remote_url, data = None try: data = json.loads(r.content.decode('utf-8')) + except UnicodeDecodeError: + # If the decoding fails, switch to slower but probably working .json() + try: + logging.warning("UTF-8 content.decode failed, switching to slower .json method") + data = r.json() + except Exception as e: + raise e except Exception as e: traceback.print_exc() raise RuntimeError( From b197491a86326d50763f88472928e279836099bb Mon Sep 17 00:00:00 2001 From: Steffen Schwebel Date: Tue, 25 May 2021 12:44:07 +0200 Subject: [PATCH 3/3] remove traceback --- powerdnsadmin/lib/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/powerdnsadmin/lib/utils.py b/powerdnsadmin/lib/utils.py index 6caa88c..d086e81 100644 --- a/powerdnsadmin/lib/utils.py +++ b/powerdnsadmin/lib/utils.py @@ -4,7 +4,6 @@ import json import requests import hashlib import ipaddress -import traceback from collections.abc import Iterable from distutils.version import StrictVersion @@ -113,7 +112,6 @@ def fetch_json(remote_url, except Exception as e: raise e except Exception as e: - traceback.print_exc() raise RuntimeError( 'Error while loading JSON data from {0}'.format(remote_url)) from e return data