From 34246a00e7be8da59ed4e0d659f7b980a5da7910 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 27 Aug 2017 10:20:36 -0400 Subject: [PATCH] Fix #2673: JSON file encoding in absubmit First, it's best to open the file as binary so the JSON module itself can figure out how to decode it (it will just use UTF-8). Then, we can use `load` instead of `loads` to avoid needing to read the file explicitly ourselves. --- beetsplug/absubmit.py | 4 ++-- docs/changelog.rst | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index 3d21c469cb..0c288b9d83 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -133,8 +133,8 @@ def _get_analysis(self, item): item=item, error=e ) return None - with open(filename) as tmp_file: - analysis = json.loads(tmp_file.read()) + with open(filename, 'rb') as tmp_file: + analysis = json.load(tmp_file) # Add the hash to the output. analysis['metadata']['version']['essentia_build_sha'] = \ self.extractor_sha diff --git a/docs/changelog.rst b/docs/changelog.rst index 2e4f1be545..413cf0df01 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -35,6 +35,8 @@ Fixes: music. :bug:`2667` * :doc:`/plugins/chroma`: Fix a crash when running the ``submit`` command on Python 3 on Windows with non-ASCII filenames. :bug:`2671` +* :doc:`/plugins/absubmit`: Fix an occasional crash on Python 3 when the AB + analysis tool produced non-ASCII metadata. :bug:`2673` For developers: