From 80fae5eae7f76d8ba8590e53a6dc49010d1f0dbb Mon Sep 17 00:00:00 2001 From: mariodcosta Date: Mon, 11 Apr 2022 10:45:21 +0100 Subject: [PATCH] Compatibility with python 3 To maximize the compatibility with python 3 --- query_xforce_exchange.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/query_xforce_exchange.py b/query_xforce_exchange.py index 5942c96..ac5af03 100644 --- a/query_xforce_exchange.py +++ b/query_xforce_exchange.py @@ -25,12 +25,20 @@ def get_md5(filename): if __name__ == "__main__": key = "" # https://exchange.xforce.ibmcloud.com/settings/api password ="" - + + #for python 2.7 encode token in base64 in this way token = base64.b64encode(key + ":" + password) + + #for python 3 use these 3 lines to encode token + ''' + token_bytes = (key + ":" + password).encode("ascii") + base64_bytes = base64.b64encode(token_bytes) + token = base64_bytes.decode("ascii") + ''' + headers = {'Authorization': "Basic " + token, 'Accept': 'application/json'} url = "https://api.xforce.ibmcloud.com:443" - - + parser = OptionParser() parser.add_option("-u", "--url", dest="s_url", default=None, help="URL to be checked by Exchange IBM Xforce", metavar="scanurl")