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:
parent
3548bcfd87
commit
cf08f14bed
|
@ -13,11 +13,15 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from urllib import parse as urlparse
|
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_log import log
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
|
@ -26,7 +30,6 @@ from vmware_nsxlib._i18n import _
|
||||||
from vmware_nsxlib.v3 import constants
|
from vmware_nsxlib.v3 import constants
|
||||||
from vmware_nsxlib.v3 import exceptions
|
from vmware_nsxlib.v3 import exceptions
|
||||||
from vmware_nsxlib.v3 import utils
|
from vmware_nsxlib.v3 import utils
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
NULL_CURSOR_PREFIX = '0000'
|
NULL_CURSOR_PREFIX = '0000'
|
||||||
|
@ -35,7 +38,7 @@ NULL_CURSOR_PREFIX = '0000'
|
||||||
def get_http_error_details(response):
|
def get_http_error_details(response):
|
||||||
try:
|
try:
|
||||||
msg = response.json() if response.content else ''
|
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)
|
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
|
# error_code can't be None else it can't be casted to an exception
|
||||||
return {'status_code': response.status_code,
|
return {'status_code': response.status_code,
|
||||||
|
|
Loading…
Reference in New Issue