summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Yang <Bin.Yang@windriver.com>2019-09-27 02:17:39 +0000
committerBin Yang <Bin.Yang@windriver.com>2019-09-27 03:18:34 +0000
commitf3ac12c0056d9db7878bc52c2f3a27171bd5995f (patch)
treeab5b69a856ac3e499b4768eb34b4d85ebba741ef
parentcba35332711747a9af0f8bf8412f88fadf5e93e3 (diff)
Fix restcall bug of decode http response content
Issue-ID: MULTICLOUD-835 Signed-off-by: Bin Yang <Bin.Yang@windriver.com> Change-Id: Ib6fa7d2bece2e3160babf1139fd8b73e19a34a9a
-rw-r--r--multivimbroker/multivimbroker/pub/utils/restcall.py4
-rw-r--r--multivimbroker/multivimbroker/tests/test_restcall.py2
2 files changed, 4 insertions, 2 deletions
diff --git a/multivimbroker/multivimbroker/pub/utils/restcall.py b/multivimbroker/multivimbroker/pub/utils/restcall.py
index 62dd301..7070824 100644
--- a/multivimbroker/multivimbroker/pub/utils/restcall.py
+++ b/multivimbroker/multivimbroker/pub/utils/restcall.py
@@ -20,6 +20,7 @@ import urllib.error
import uuid
import httplib2
import base64
+import codecs
from multivimbroker.pub.config.config import AAI_SCHEMA_VERSION
from multivimbroker.pub.config.config import AAI_SERVICE_URL
@@ -98,7 +99,8 @@ def call_req(base_url, user, passwd, auth_type, resource, method,
resp, resp_content = http.request(
full_url, method=method.upper(),
body=content, headers=headers)
- resp_status, resp_body = resp['status'], resp_content
+ resp_status, resp_body = resp['status'], codecs.decode(
+ resp_content, 'UTF-8') if resp_content else None
if resp_status in status_ok_list:
ret = [0, resp_body, resp_status, resp]
diff --git a/multivimbroker/multivimbroker/tests/test_restcall.py b/multivimbroker/multivimbroker/tests/test_restcall.py
index ea70dff..aff2670 100644
--- a/multivimbroker/multivimbroker/tests/test_restcall.py
+++ b/multivimbroker/multivimbroker/tests/test_restcall.py
@@ -60,7 +60,7 @@ class TestRestCall(unittest.TestCase):
"status": "200"
}
resp_content = "hello"
- mock_req.return_value = mock_resp, resp_content
+ mock_req.return_value = mock_resp, resp_content.encode("utf-8")
expect_ret = [0, resp_content, "200", mock_resp]
ret = restcall.call_req("http://onap.org/", "user", "pass",
restcall.rest_no_auth, "vim", "GET")