resolve python2->python3 issues
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / utils / restcall.py
index 6bcb033..08c33c5 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import base64
 import sys
 import traceback
 import logging
-import urllib2
+import urllib.error
 import uuid
 import httplib2
 
@@ -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)
@@ -62,7 +63,7 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content='', ad
                     ret = [1, "Unable to connect to %s" % full_url, resp_status]
                     continue
                 raise ex
-    except urllib2.URLError as err:
+    except urllib.error.URLError as err:
         ret = [2, str(err), resp_status]
     except Exception as ex:
         logger.error(traceback.format_exc())