Fix restcall authorization issue 05/91505/1
authorOlivia.Zhan <zhan.jie1@zte.com.cn>
Tue, 16 Jul 2019 08:48:53 +0000 (16:48 +0800)
committerOlivia.Zhan <zhan.jie1@zte.com.cn>
Tue, 16 Jul 2019 08:48:53 +0000 (16:48 +0800)
Issue-ID: VFC-1429
Signed-off-by: Olivia.Zhan <zhan.jie1@zte.com.cn>
Change-Id: I3ab25ae88642b726452bf5f1f516479baf31bd5c

genericparser/pub/utils/restcall.py

index c83f69d..5efa0cb 100644 (file)
@@ -18,6 +18,7 @@ import logging
 import urllib
 import uuid
 import httplib2
+import base64
 
 from genericparser.pub.config.config import MSB_SERVICE_IP, MSB_SERVICE_PORT
 
@@ -39,7 +40,7 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content='', ad
         full_url = combine_url(base_url, resource)
         headers = {'content-type': 'application/json', 'accept': 'application/json'}
         if user:
-            headers['Authorization'] = 'Basic ' + ('%s:%s' % (user, passwd)).encode("base64")
+            headers['Authorization'] = 'Basic %s' % base64.b64encode(bytes('%s:%s' % (user, passwd), "utf-8")).decode()
         ca_certs = None
         if additional_headers:
             headers.update(additional_headers)