(Feb-27-2020, 08:41 AM)BellaMac Wrote: invalid json: 'charmap' codec can't decode byte 0x81 in position 145717: character maps to <undefined>Remember on Widows should and most in many cases most specify which encoding that should be used.
I also discovered that if I enter (python -m json.tool "C:\Engineering\test2\assetLink_tr-TR.json") on the CMD line, it works as what I am looking for. But I would still like to find out why the script does not work on UTF-8 JSON files.
If not it will use
charmap
codec.with open(fname, encoding='utf-8') as f:The default encoding for Python 3 source code is
utf-8
,but read in and out OS may mess that up.So as example both read and write do specify what encoding to use,
and that's always
utf-8
if code starts in Python or as a first try in almost all cases.s = 'Crème and Spicy jalapeño ☂' with open('unicode.txt', 'w', encoding='utf-8') as f_out: f_out.write(s) with open('unicode.txt', encoding='utf-8') as f: print(f.read())
Output:Crème and Spicy jalapeño ☂