Browse Source

Fix json UTF8 dumping in Python 2

master
Georg Sauthoff 2 years ago
parent
commit
6ad0d4dadd
  1. 7
      examples/products.py

7
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)

Loading…
Cancel
Save