Fall back to ValueError if JSONDecodeError is not available (#38276) (#38423)

(cherry picked from commit e05cad785e)
This commit is contained in:
Nathaniel Case 2018-04-11 09:01:47 -04:00 committed by GitHub
parent 23e57fe095
commit 8b8455523d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -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:

View file

@ -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: