From 0ff7724860bfc0edb11f0c1a0bf03a3fd10831c0 Mon Sep 17 00:00:00 2001 From: cvzi Date: Fri, 20 Sep 2024 21:29:03 +0200 Subject: [PATCH] Use binary mode when opening JSON files to avoid UnicodeDecodeError: 'ascii' codec can't decode byte... --- emoji/unicode_codes/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/emoji/unicode_codes/__init__.py b/emoji/unicode_codes/__init__.py index a46b8da..2624907 100644 --- a/emoji/unicode_codes/__init__.py +++ b/emoji/unicode_codes/__init__.py @@ -78,7 +78,9 @@ def __missing__(self, key: str) -> str: def _load_default_from_json(): global EMOJI_DATA global _loaded_keys - with open(Path(__file__).with_name('emoji.json')) as f: + + file = Path(__file__).with_name('emoji.json') + with open(file, 'rb') as f: EMOJI_DATA = dict(json.load(f, object_pairs_hook=EmojiDataDict)) # type: ignore _loaded_keys = list(_DEFAULT_KEYS) @@ -93,7 +95,7 @@ def load_from_json(key: str): raise NotImplementedError('Language not supported', key) file = Path(__file__).with_name(f'emoji_{key}.json') - with open(file) as f: + with open(file, 'rb') as f: for emj, value in json.load(f).items(): EMOJI_DATA[emj][key] = value # type: ignore