diff options
Diffstat (limited to 'vnftest/common/rest_client.py')
-rw-r--r-- | vnftest/common/rest_client.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/vnftest/common/rest_client.py b/vnftest/common/rest_client.py index 23a108c..051f5dd 100644 --- a/vnftest/common/rest_client.py +++ b/vnftest/common/rest_client.py @@ -14,9 +14,17 @@ ############################################################################## import json + +import logging +import os import urllib2 import requests +from vnftest.common import utils + +logger = logging.getLogger(__name__) +os.putenv('PYTHONHTTPSVERIFY', "0") + def post(url, headers, data, logger): return call(url, 'POST', headers, data, logger) @@ -31,10 +39,15 @@ def call(url, method, headers, data, logger): f = urllib2.urlopen(req) return_code = f.code response_body = f.read() + headers = f.headers + content_type = headers.dict['content-type'] if 'content-type' in headers.dict else 'application/json' f.close() if len(str(response_body)) == 0: response_body = "{}" - response_body = json.loads(response_body) + if 'application/xml' in content_type: + response_body = utils.xml_to_dict(response_body) + else: + response_body = json.loads(response_body) result = {'return_code': return_code, 'body': response_body} return result |