UnicodeEncodeError: 'charmap' codec can't encode character '\x9d' in position 656: character maps to <undefined> code example

Example 1: charmap' codec can't encode character '\u010d' in position 97: character maps to

import io
with io.open(fname, "w", encoding="utf-8") as f:
    f.write(html)

Example 2: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 92: character maps to

#that's worked for me 

file = open(filepath,"r", encoding="utf8")

Example 3: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 92: character maps to

file = open(filename, encoding="cp437")