kadranel / python-volafile-downloader

volafile downloader based on python-volapi
MIT License
14 stars 7 forks source link

UnicodeEncodeError: 'charmap' codec can't encode characters #6

Closed tarchive closed 3 years ago

tarchive commented 4 years ago

Often closes due to character encoding. Can you add some way to handle the characters charmap does not support?

Traceback (most recent call last):
  File "python-volafile-downloader-master\downloader.py", line 398, in <module>
    main()
  File "python-volafile-downloader-master\downloader.py", line 385, in main
    v.dl()
  File "python-volafile-downloader-master\downloader.py", line 105, in dl
    self.listen.listen()
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 507, in listen
    return self.conn.listen()
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 346, in listen
    if not self.run_queues():
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 356, in run_queues
    return sum(l.process() for l in listeners) > 0
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 356, in <genexpr>
    return sum(l.process() for l in listeners) > 0
  File "C:\Python37-64\lib\site-packages\volapi\auxo.py", line 243, in process
    if cb(item) is False:
  File "python-volafile-downloader-master\downloader.py", line 87, in onmessage
    self.log_room(m)
  File "python-volafile-downloader-master\downloader.py", line 130, in log_room
    fl.write(log_msg)
  File "C:\Python37-64\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 '\U0001f438' in position 39: character maps to <undefined>

and

Traceback (most recent call last):
  File "python-volafile-downloader-master\downloader.py", line 398, in <module>
    main()
  File "python-volafile-downloader-master\downloader.py", line 385, in main
    v.dl()
  File "python-volafile-downloader-master\downloader.py", line 105, in dl
    self.listen.listen()
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 507, in listen
    return self.conn.listen()
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 346, in listen
    if not self.run_queues():
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 356, in run_queues
    return sum(l.process() for l in listeners) > 0
  File "C:\Python37-64\lib\site-packages\volapi\volapi.py", line 356, in <genexpr>
    return sum(l.process() for l in listeners) > 0
  File "C:\Python37-64\lib\site-packages\volapi\auxo.py", line 243, in process
    if cb(item) is False:
  File "python-volafile-downloader-master\downloader.py", line 87, in onmessage
    self.log_room(m)
  File "python-volafile-downloader-master\downloader.py", line 130, in log_room
    fl.write(log_msg)
  File "C:\Python37-64\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 44-45: character maps to <undefined>
tarchive commented 4 years ago

I fixed my issue by adding the utf-8 encoding to the open function.

Edit downloader.py file Change line 124 to fl = open(path, "w+", encoding='utf-8') Change line 126 to fl = open(path, "a", encoding='utf-8') Save and rerun the downloader

Please note i am not a python coder, just a proficient Googler. The modification here fixes my issue but may not completely fix the entire problem or be done in the correct way. For that reason, I doubt i'll make a Pull Request of this myself so please go ahead and incorporate my findings and submit your own.

Until a permanent fix has been implemented, this issue will remain open.

source: https://stackoverflow.com/a/52706404