Merge "Support two json decoder exception" into stable/xena

This commit is contained in:
Zuul 2022-06-30 16:02:37 +00:00 committed by Gerrit Code Review
commit a10a487202
1 changed files with 6 additions and 3 deletions

View File

@ -13,11 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
#
import json
import re
import time
from urllib import parse as urlparse
try:
from simplejson.errors import JSONDecodeError
except ImportError:
from json.decoder import JSONDecodeError
from oslo_log import log
from oslo_serialization import jsonutils
import requests
@ -26,7 +30,6 @@ from vmware_nsxlib._i18n import _
from vmware_nsxlib.v3 import constants
from vmware_nsxlib.v3 import exceptions
from vmware_nsxlib.v3 import utils
LOG = log.getLogger(__name__)
NULL_CURSOR_PREFIX = '0000'
@ -35,7 +38,7 @@ NULL_CURSOR_PREFIX = '0000'
def get_http_error_details(response):
try:
msg = response.json() if response.content else ''
except json.decoder.JSONDecodeError as e:
except JSONDecodeError as e:
LOG.debug("decode response %s error %s", response.content, e)
# error_code can't be None else it can't be casted to an exception
return {'status_code': response.status_code,