skadogg/personal-tv-guide

๐Ÿ› UnicodeEncodeError: 'charmap' codec can't encode character

Closed this issue ยท 2 comments

This part of the code returns a random show for the Featured Film section. I don't know which show was picked in this case, so I'm not sure where to start. The character in question is a "ฤ" (LATIN SMALL LETTER C WITH CARON (U+10D)). The error seems to be in some external module.

DevTools listening on ws://127.0.0.1:52522/devtools/browser/4f0efb11-dd01-4f49-adaa-66120677caa7
<โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– > 1 in 1.0s (4.89/s)
<โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– โ– > 0 in 0.1s (0.00/s)
Traceback (most recent call last):
  File "c:\Users\gunner\Documents\git\personal-tv-guide\run.py", line 121, in <module>
    html_handle.write(modules.html.generate_featured_film_table(modules.justwatch.get_random_show(data_list_everything)))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u010d' in position 439: character maps to <undefined>
PS C:\Users\gunner\Documents\git\personal-tv-guide> `

Hi @skadogg , it's an encoding error.

In the code the file is opened like this :

html_handle = open(outfile, '+w')

You need to specify encoding here like this :

html_handle = open(outfile, '+w', encoding="utf-8")

This should resolve your problem. I am opening a PR for this.

Oh, great! I'm glad it's something simple. I'll check this out later today.