Support two json decoder exception

If simplejson installed, requests will use simplejson to handle the
deserialization of the JSON.  if not installed, requests will use
json package

Change-Id: I64a54d105d6d533c2d75174bbf265b1d372b9b88
This commit is contained in:
Tao Zou 2022-06-29 14:30:08 +08:00
parent 3548bcfd87
commit cf08f14bed
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,