diff --git a/lbrynet/dht/distance.py b/lbrynet/dht/distance.py index 2c93ae9c2..f603c7c2d 100644 --- a/lbrynet/dht/distance.py +++ b/lbrynet/dht/distance.py @@ -1,4 +1,9 @@ +from binascii import hexlify + from lbrynet.dht import constants +import sys +if sys.version_info > (3,): + long = int class Distance(object): @@ -12,10 +17,10 @@ class Distance(object): if len(key) != constants.key_bits / 8: raise ValueError("invalid key length: %i" % len(key)) self.key = key - self.val_key_one = long(key.encode('hex'), 16) + self.val_key_one = long(hexlify(key), 16) def __call__(self, key_two): - val_key_two = long(key_two.encode('hex'), 16) + val_key_two = long(hexlify(key_two), 16) return self.val_key_one ^ val_key_two def is_closer(self, a, b): diff --git a/tests/unit/dht/test_kbucket.py b/tests/unit/dht/test_kbucket.py index 100f63562..cf23ac908 100644 --- a/tests/unit/dht/test_kbucket.py +++ b/tests/unit/dht/test_kbucket.py @@ -14,7 +14,7 @@ from lbrynet.dht import constants def address_generator(address=(10, 42, 42, 1)): def increment(addr): - value = struct.unpack("I", "".join([chr(x) for x in list(addr)[::-1]]))[0] + 1 + value = struct.unpack("I", "".join([chr(x) for x in list(addr)[::-1]]).encode())[0] + 1 new_addr = [] for i in range(4): new_addr.append(value % 256)