From 36117dacfa3a4e47923b96c35f323bd6e9a6103e Mon Sep 17 00:00:00 2001 From: Jon Clucas Date: Tue, 27 Feb 2018 16:12:08 -0500 Subject: [PATCH] =?UTF-8?q?:ambulance:=20=F0=9F=90=8D3=20Encode=20Unicode-?= =?UTF-8?q?Objects=20Before=20Hashing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - In Python3, `hashlib.md5(json.dumps(val).hexdigest()` returned > TypeError: Unicode-objects must be encoded before hashing for (at least) strings, lists, and dictionaries. Add `.encode("utf8")` to rectify. Related ibm-watson-data-lab/pixiedust_node#10 --- pixiedust_node/node.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pixiedust_node/node.py b/pixiedust_node/node.py index 3edfd73..46b0de4 100644 --- a/pixiedust_node/node.py +++ b/pixiedust_node/node.py @@ -41,12 +41,12 @@ def clearCache(self): # the cache contains the key (variable name) against an MD5 of the # JSON form of the value. This makes the cache more compact. def setCache(self, key, val): - self.cache[key] = hashlib.md5(json.dumps(val)).hexdigest() + self.cache[key] = hashlib.md5(json.dumps(val).encode("utf8")).hexdigest() # check whether key is in cache and whether it equals val by comparing # the hash of its JSON value with what's in the cache def inCache(self, key, val): - hash = hashlib.md5(json.dumps(val)).hexdigest() + hash = hashlib.md5(json.dumps(val).encode("utf8")).hexdigest() return (key in self.cache and self.cache[key] == hash) def post_execute(self): @@ -212,7 +212,7 @@ def __init__(self, path): # watch Python variables for changes self.vw = VarWatcher(get_ipython(), self.ps) - + # create thread to read this process's output NodeStdReader(self.ps, self.vw) @@ -275,6 +275,3 @@ def uninstall(self, module): def list(self): self.cmd('list', None) - - -