Skip to content

Commit

Permalink
Merge pull request #8 from natl/master
Browse files Browse the repository at this point in the history
Added try/except statement for invalid unicode characters in heade
  • Loading branch information
eyurtsev authored Jan 25, 2017
2 parents dc1fdee + f16f21c commit cb64539
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fcsparser/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ def read_text(self, file_handle):
# There are some differences in how the
file_handle.seek(header['text start'], 0)
raw_text = file_handle.read(header['text end'] - header['text start'] + 1)
raw_text = raw_text.decode('utf-8')
try:
raw_text = raw_text.decode('utf-8')
except UnicodeDecodeError as e:
print("Encountered an illegal utf-8 byte in the header.\n" +
"Illegal utf-8 characters will be ignored.\n" +
"The illegal byte was {} at position {}".format(
repr(e.object[e.start]), e.start))
raw_text = raw_text.decode('utf-8', 'ignore')

#####
# Parse the TEXT segment of the FCS file into a python dictionary
Expand Down

0 comments on commit cb64539

Please sign in to comment.