Skip to content

Error with encoding #4

@aKim8o

Description

@aKim8o

Hi found that I received an error message when I coded along with the tutorial:

Traceback (most recent call last): File "C:\Users\XXX\PycharmProjects\bs4-start\main.py", line 5, in <module> contents = file.read() ^^^^^^^^^^^ File "C:\Users\XXX\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 281: character maps to <undefined>

To fix this, I needed to add an encoding value to the BeautifulSoup Class like so:

with open("website.html", **encoding="utf-8"**) as file:

hope this helps other people encountering the same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions