From 8b8455523d6709e53dfd5a7f082740c548636032 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Wed, 11 Apr 2018 09:01:47 -0400 Subject: [PATCH] Fall back to ValueError if JSONDecodeError is not available (#38276) (#38423) (cherry picked from commit e05cad785eeaa0eb84f2ebdb1022f01452779b09) --- lib/ansible/executor/task_executor.py | 3 ++- lib/ansible/plugins/connection/persistent.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 2efee392c54..c225b2d425e 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -895,7 +895,8 @@ class TaskExecutor: else: try: result = json.loads(to_text(stderr, errors='surrogate_then_replace')) - except json.decoder.JSONDecodeError: + except getattr(json.decoder, 'JSONDecodeError', ValueError): + # JSONDecodeError only available on Python 3.5+ result = {'error': to_text(stderr, errors='surrogate_then_replace')} if 'messages' in result: diff --git a/lib/ansible/plugins/connection/persistent.py b/lib/ansible/plugins/connection/persistent.py index 1e377a75dd0..ac2406f4c1a 100644 --- a/lib/ansible/plugins/connection/persistent.py +++ b/lib/ansible/plugins/connection/persistent.py @@ -115,7 +115,8 @@ class Connection(ConnectionBase): else: try: result = json.loads(to_text(stderr, errors='surrogate_then_replace')) - except json.decoder.JSONDecodeError: + except getattr(json.decoder, 'JSONDecodeError', ValueError): + # JSONDecodeError only available on Python 3.5+ result = {'error': to_text(stderr, errors='surrogate_then_replace')} if 'messages' in result: