Fix json UTF8 dumping in Python 2

This commit is contained in:
Georg Sauthoff 2019-07-15 19:41:49 +02:00
parent 77d55b4f48
commit 6ad0d4dadd
1 changed files with 5 additions and 2 deletions

View File

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