Unicode decoding error: how to skip invalid characters

Is there a way to preprogram text files and skip these characters?

UnicodeDecodeError: 'utf8' codec can't decode byte 0xa1 in position 1395: invalid start byte
0
source share
2 answers

Try the following:

str.decode('utf-8',errors='ignore')
+7
source

I think your text file has a special character, so "utf-8" cannot be decoded.

You need to try using "ISO-8859-1" instead of "utf-8". eg:

   import sys
   reload(sys).setdefaultencoding("ISO-8859-1")

   # put your code here
+2
source

Source: https://habr.com/ru/post/1541362/


All Articles