From ebc145be5e15c64a31ba496625727a7308a57baf Mon Sep 17 00:00:00 2001 From: Anh Vo Date: Wed, 15 Jul 2020 16:57:43 -0400 Subject: DataSourceAzure: Use ValueError when JSONDecodeError is not available (#490) JSONDecodeError is only available in Python 3.5+. When it isn't available (i.e. on Python 3.4, which cloud-init still supports) use the more generic ValueError. --- cloudinit/sources/DataSourceAzure.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cloudinit/sources/DataSourceAzure.py') diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 8b34d047..068537ee 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -8,7 +8,6 @@ import base64 import contextlib import crypt from functools import partial -import json import os import os.path import re @@ -1436,9 +1435,15 @@ def _get_metadata_from_imds(retries): report_diagnostic_event(msg) LOG.debug(msg) return {} + try: + from json.decoder import JSONDecodeError + json_decode_error = JSONDecodeError + except ImportError: + json_decode_error = ValueError + try: return util.load_json(str(response)) - except json.decoder.JSONDecodeError as e: + except json_decode_error as e: report_diagnostic_event('non-json imds response' % e) LOG.warning( 'Ignoring non-json IMDS instance metadata: %s', str(response)) -- cgit v1.2.3