diff --git a/beets/importer.py b/beets/importer.py index bfaa21a01..ca035dc7d 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -69,7 +69,7 @@ class ImportAbort(Exception): def _open_state(): """Reads the state file, returning a dictionary.""" try: - with open(config['statefile'].as_filename()) as f: + with open(config['statefile'].as_filename(), 'rb') as f: return pickle.load(f) except Exception as exc: # The `pickle` module can emit all sorts of exceptions during @@ -83,7 +83,7 @@ def _open_state(): def _save_state(state): """Writes the state dictionary out to disk.""" try: - with open(config['statefile'].as_filename(), 'w') as f: + with open(config['statefile'].as_filename(), 'wb') as f: pickle.dump(state, f) except IOError as exc: log.error(u'state file could not be written: {0}', exc) diff --git a/test/test_importer.py b/test/test_importer.py index e83f9e89c..8f372e841 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -1341,8 +1341,8 @@ class IncrementalImportTest(unittest.TestCase, TestHelper): def test_invalid_state_file(self): importer = self.create_importer() - with open(self.config['statefile'].as_filename(), 'w') as f: - f.write('000') + with open(self.config['statefile'].as_filename(), 'wb') as f: + f.write(b'000') importer.run() self.assertEqual(len(self.lib.albums()), 1)