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.
This commit is contained in:
Ameya Shenoy 2018-05-08 15:41:12 +05:30 committed by Faris Ansari
parent 6737f1912c
commit fc99d691d1

View file

@ -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]