From 6ad0d4dadd1bd84f1fb758e1fcd74e2b012670ce Mon Sep 17 00:00:00 2001 From: Georg Sauthoff Date: Mon, 15 Jul 2019 19:41:49 +0200 Subject: [PATCH] Fix json UTF8 dumping in Python 2 --- examples/products.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/products.py b/examples/products.py index 4142de3..a0c3977 100755 --- a/examples/products.py +++ b/examples/products.py @@ -11,6 +11,9 @@ import sys if sys.version_info.major >= 3: unicode = str + encode = lambda x : x +else: + encode = lambda x : x.encode('utf8') # you have to fill the below with your login details for the ProdWS Service USER = "xxx" @@ -40,8 +43,8 @@ if data['success']: 'max_weight': unicode(weight['maxValue']) } - json.dump(products, sys.stdout, - sort_keys=True, indent=4, ensure_ascii=False) + print(encode(json.dumps(products, + sort_keys=True, indent=4, ensure_ascii=False))) print('') else: print('ERROR: %s' % data['Exception'], file=sys.stderr)