Skip to content

Commit 3533925

Browse files
author
Naor Livne
committed
changing base64 encoding to support python3 & python2
1 parent c4af4a0 commit 3533925

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

NebulaPythonSDK/sdk.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import requests, base64, json
1+
import requests, base64, json, six
2+
3+
def b64encode(source):
4+
if six.PY3:
5+
source = source.encode('utf-8')
6+
content = base64.b64encode(source).decode('utf-8')
27

38

49
class Nebula:
@@ -17,7 +22,10 @@ def __init__(self, username=None, password=None, host="127.0.0.1", port=80, prot
1722
'cache-control': "no-cache"
1823
}
1924
if username is not None and password is not None:
20-
self.basic_auth = base64.b64encode(username + ":" + password)
25+
user_pass_combo = username + ":" + password
26+
if six.PY3 is True:
27+
user_pass_combo = user_pass_combo.encode('utf-8')
28+
self.basic_auth = base64.b64encode(user_pass_combo)
2129
self.headers["authorization"] = "Basic " + self.basic_auth
2230
self.API_VERSION = "v2"
2331

0 commit comments

Comments
 (0)