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:
parent
6737f1912c
commit
fc99d691d1
1 changed files with 3 additions and 2 deletions
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue