← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-json-decode-errors into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-json-decode-errors into launchpad:master.

Commit message:
Weaken detection of JSON decode errors

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396661

requests actually uses simplejson internally if it's available in the environment (which it is), so catching json.decoder.JSONDecodeError doesn't work.  Just catch ValueError; it's what we've been doing on Python 2 anyway, so is clearly not a major problem.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-json-decode-errors into launchpad:master.
diff --git a/lib/lp/oci/model/ociregistryclient.py b/lib/lp/oci/model/ociregistryclient.py
index 845abf5..e4aa271 100644
--- a/lib/lp/oci/model/ociregistryclient.py
+++ b/lib/lp/oci/model/ociregistryclient.py
@@ -15,10 +15,6 @@ from functools import partial
 import hashlib
 from io import BytesIO
 import json
-try:
-    from json.decoder import JSONDecodeError
-except ImportError:
-    JSONDecodeError = ValueError
 import logging
 import re
 import tarfile
@@ -94,7 +90,7 @@ class OCIRegistryClient:
         if response.content:
             try:
                 response_data = response.json()
-            except JSONDecodeError:
+            except ValueError:
                 pass
             else:
                 errors = response_data.get("errors")
diff --git a/lib/lp/scripts/utilities/importpedant.py b/lib/lp/scripts/utilities/importpedant.py
index 5176e43..d46b863 100644
--- a/lib/lp/scripts/utilities/importpedant.py
+++ b/lib/lp/scripts/utilities/importpedant.py
@@ -32,8 +32,6 @@ valid_imports_not_in_all = {
     # Exported in Python 3, but missing and so not exported in Python 2.
     'contextlib': set(['ExitStack']),
     'importlib': set(['resources']),
-    # Exported in Python 3, but missing and so not exported in Python 2.
-    'json.decoder': set(['JSONDecodeError']),
     'openid.fetchers': set(['Urllib2Fetcher']),
     'openid.message': set(['NamespaceAliasRegistrationError']),
     # Exported as shlex.quote in Python 3.
diff --git a/lib/lp/snappy/model/snapstoreclient.py b/lib/lp/snappy/model/snapstoreclient.py
index 9d007de..917559d 100644
--- a/lib/lp/snappy/model/snapstoreclient.py
+++ b/lib/lp/snappy/model/snapstoreclient.py
@@ -12,10 +12,6 @@ __all__ = [
 
 import base64
 import json
-try:
-    from json.decoder import JSONDecodeError
-except ImportError:
-    JSONDecodeError = ValueError
 import string
 import time
 
@@ -225,7 +221,7 @@ class SnapStoreClient:
         if requests_error.response.content:
             try:
                 response_data = requests_error.response.json()
-            except JSONDecodeError:
+            except ValueError:
                 pass
             else:
                 if "error_list" in response_data:
@@ -432,7 +428,7 @@ class SnapStoreClient:
         if cached_channels is not None:
             try:
                 channels = json.loads(cached_channels)
-            except JSONDecodeError:
+            except ValueError:
                 log.exception(
                     "Cannot load cached channels for %s; deleting" %
                     search_host)