Fix json UTF8 dumping in Python 2
This commit is contained in:
parent
77d55b4f48
commit
6ad0d4dadd
|
@ -11,6 +11,9 @@ import sys
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
if sys.version_info.major >= 3:
|
||||||
unicode = str
|
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
|
# you have to fill the below with your login details for the ProdWS Service
|
||||||
USER = "xxx"
|
USER = "xxx"
|
||||||
|
@ -40,8 +43,8 @@ if data['success']:
|
||||||
'max_weight': unicode(weight['maxValue'])
|
'max_weight': unicode(weight['maxValue'])
|
||||||
}
|
}
|
||||||
|
|
||||||
json.dump(products, sys.stdout,
|
print(encode(json.dumps(products,
|
||||||
sort_keys=True, indent=4, ensure_ascii=False)
|
sort_keys=True, indent=4, ensure_ascii=False)))
|
||||||
print('')
|
print('')
|
||||||
else:
|
else:
|
||||||
print('ERROR: %s' % data['Exception'], file=sys.stderr)
|
print('ERROR: %s' % data['Exception'], file=sys.stderr)
|
||||||
|
|
Loading…
Reference in New Issue