From fc99d691d13cfe79f393e9a66c034c7280c97c09 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Tue, 8 May 2018 15:41:12 +0530 Subject: [PATCH] Fix python3 issue reading pdf (#5541) File types other than plain text files weren't sent properly in email. The initial implementation of try except used to destroy the file object in the try statement, and hence we were getting a blank string in the except block. The fix involves reading the file object separately before trying to decode it. --- frappe/utils/file_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/utils/file_manager.py b/frappe/utils/file_manager.py index 5b3ae220a8..258d62daee 100644 --- a/frappe/utils/file_manager.py +++ b/frappe/utils/file_manager.py @@ -303,12 +303,13 @@ def get_file(fname): content = f.read() else: with io.open(encode(file_path), mode='rb') as f: + content = f.read() try: # for plain text files - content = f.read().decode() + content = content.decode() except UnicodeDecodeError: # for .png, .jpg, etc - content = f.read() + pass return [file_path.rsplit("/", 1)[-1], content]