From f46202370626a2c1312d09929f13ed27cde77a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Faure-Lacroix?= Date: Thu, 18 Oct 2018 00:55:39 +0300 Subject: [PATCH] [11.0 BUGFIX] Pass bytes to Ofxparse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ofx files have the correct charset inside their headers and trying to convert the file to StringIO using a particular encoding is subject to failures when the file isn't exactly an ascii file. For example a file encoded with CP1252 with accents on letters like é or è will not be parser as utf-8 and will fail to load. Also since OfxParse is supposed to receive a file handle, it is correctly reading the file header and choosing the appropriate charset to read the rest of the file. For this reason, pass the bytes as a ByteIO that doesn't care about the encoding. --- .../wizard/account_bank_statement_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_bank_statement_import_ofx/wizard/account_bank_statement_import.py b/account_bank_statement_import_ofx/wizard/account_bank_statement_import.py index 4258759b..8944add3 100644 --- a/account_bank_statement_import_ofx/wizard/account_bank_statement_import.py +++ b/account_bank_statement_import_ofx/wizard/account_bank_statement_import.py @@ -39,7 +39,7 @@ class AccountBankStatementImport(models.TransientModel): if not OfxParser: return False try: - ofx = OfxParser.parse(io.StringIO(data_file.decode('utf-8'))) + ofx = OfxParser.parse(io.BytesIO(data_file)) except Exception as e: _logger.debug(e) return False