can’t encode character ‘\u0144’ even using encoding=utf-8 in python3

I am trying to read some information from some .txt files, they are all in english and they do not have any other unicode character, the problem is that for an especific file it just crashed and do not show the information, the error is

Traceback (most recent call last):
  File "C:\users\bienvenido\desktop\programmacion\harvard\cs50 artificial inteligence\6\questions\questions.py", line 107, in <module>
    main()
  File "C:\users\bienvenido\desktop\programmacion\harvard\cs50 artificial inteligence\6\questions\questions.py", line 16, in main
    files = load_files(sys.argv[1])
  File "C:\users\bienvenido\desktop\programmacion\harvard\cs50 artificial inteligence\6\questions\questions.py", line 59, in load_files
    files[file] = f.read()
  File "C:\Users\BIENVENIDO\AppData\Local\Programs\Python\Python39\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 38619: character maps to <undefined>

and what i am doing is

with open(os.path.join(directory,file), encoding='utf-8') as f:
    files[file] = f.read()

I also tried utf16 and default encoding



Read more here: https://stackoverflow.com/questions/67931271/cant-encode-character-u0144-even-using-encoding-utf-8-in-python3

Content Attribution

This content was originally published by jhonny at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: