skadogg / personal-tv-guide

Python-based JustWatch scraper
GNU General Public License v3.0
6 stars 7 forks source link

🐛 UnicodeEncodeError: 'charmap' codec can't encode character #105

Closed skadogg closed 6 months ago

skadogg commented 6 months ago

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> `
code-master-ajay commented 6 months ago

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.

skadogg commented 6 months ago

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