From 977e62188aa01417ddf2965d04be0f22452f447b Mon Sep 17 00:00:00 2001 From: A_D <aunderscored@gmail.com> Date: Wed, 2 Dec 2020 15:57:42 +0200 Subject: [PATCH] Made sure to handle non-utf8 locales --- EDMC.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/EDMC.py b/EDMC.py index bc5baba2..e3af1879 100755 --- a/EDMC.py +++ b/EDMC.py @@ -173,7 +173,11 @@ sys.path: {sys.path}''' if args.j: logger.debug('Import and collate from JSON dump') # Import and collate from JSON dump - data = json.load(open(args.j)) + try: + data = json.load(open(args.j)) + except UnicodeDecodeError: + data = json.load(open(args.j, encoding='utf-8')) + config.set('querytime', int(getmtime(args.j))) else: @@ -188,7 +192,7 @@ sys.path: {sys.path}''' logfile = join(logdir, logfiles[-1]) logger.debug(f'Using logfile "{logfile}"') - with open(logfile, 'r') as loghandle: + with open(logfile, 'r', encoding='utf-8') as loghandle: for line in loghandle: try: monitor.parse_entry(line)