unicode – Python 3 UnicodeDecodeError: charmap codec cant decode byte 0x9d

unicode – Python 3 UnicodeDecodeError: charmap codec cant decode byte 0x9d

In Python 3, files are opened as text (decoded to Unicode) for you; you dont need to tell BeautifulSoup what codec to decode from.

If decoding of the data fails, thats because you didnt tell the open() call what codec to use when reading the file; add the correct codec with an encoding argument:

with open(filename, encoding=utf8) as infile:
    html = BeautifulSoup(infile, html.parser)

otherwise the file will be opened with your system default codec, which is OS dependent.

unicode – Python 3 UnicodeDecodeError: charmap codec cant decode byte 0x9d

Leave a Reply

Your email address will not be published.