From 5841bf759fe76abd48d313939c0c742956d6a34f Mon Sep 17 00:00:00 2001 From: lethliel Date: Tue, 16 Apr 2019 14:40:13 +0200 Subject: [PATCH] add exception if encoding fails and try ISO-8859-1 In some rare cases the chardet encoding detection detects a wrong encoding standard. Then we switch to latin-1 which covers most if utf-8 does not work. --- osc/util/helper.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osc/util/helper.py b/osc/util/helper.py index 2e25b73c..05808d46 100644 --- a/osc/util/helper.py +++ b/osc/util/helper.py @@ -61,5 +61,9 @@ def decode_it(obj): import chardet return obj.decode(chardet.detect(obj)['encoding']) except: - import locale - return obj.decode(locale.getlocale()[1]) + try: + import locale + return obj.decode(locale.getlocale()[1]) + except: + return obj.decode('latin-1') +