diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index f747d912..5884254e 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -47,6 +47,7 @@ qui est une description (humaine, format libre) de l'archive. """ +import chardet import datetime import glob import mimetypes @@ -203,8 +204,16 @@ class BaseArchiver(object): def get_archive_description(self, archive_id): """Return description of archive""" self.initialize() - with open(os.path.join(archive_id, "_description.txt")) as f: - descr = f.read() + filename = os.path.join(archive_id, "_description.txt") + try: + with open(filename) as f: + descr = f.read() + except UnicodeDecodeError: + # some (old) files may have saved under exotic encodings + with open(filename, "rb") as f: + data = f.read() + descr = data.decode(chardet.detect(data)["encoding"]) + return descr def create_obj_archive(self, oid: int, description: str):