I have the following lines in my code
outs = codecs.getwriter('utf-8')(sys.stdout)
# dJSON contains JSON message with non-ASCII chars
outs.write(json.dumps(dJSON,encoding='utf-8', ensure_ascii=False, indent=indent_val))
I am getting the following exception:
outs.write(json.dumps(dJSON,encoding='utf-8', ensure_ascii=False, indent=indent_val))
File "/usr/lib/python2.7/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 204, in encode
return ''.join(chunks)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)
I through that by specifying encoding='utf-8' in the json.dumps statement, I avoid this type of problem. Why a