UnicodeEncodeError


#1

https://github.com/beetbox/beets/issues/2374
https://github.com/beetbox/beets/issues/1166

I’m getting a similar issue to what is described in these two issues. I’m currently running Python 3.6.3.

Here’s the traceback. I’ve tried using Python 2.7, but I don’t know how to use vaab’s fix for it. Any help would be appreciated.

Traceback (most recent call last):
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python36-32\Scripts\beet-script.py", line 11, in <module>
    load_entry_point('beets==1.4.5', 'console_scripts', 'beet')()
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\site-packages\beets\ui\__init__.py", line 1256, in main
    _raw_main(args)
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\site-packages\beets\ui\__init__.py", line 1243, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python36-32\beetsplug\alternatives.py", line 87, in func
    opts.func(lib, opts)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python36-32\beetsplug\alternatives.py", line 52, in update
    alt.update(create=options.create)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python36-32\beetsplug\alternatives.py", line 195, in update
    for item, dest in converter.as_completed():
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python36-32\beetsplug\alternatives.py", line 324, in as_completed
    yield f.result()
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\concurrent\futures\_base.py", line 425, in result
    return self.__get_result()
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\concurrent\futures\thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python36-32\beetsplug\alternatives.py", line 247, in _convert
    self._encode(self.convert_cmd, item.path, dest)
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\site-packages\beetsplug\convert.py", line 213, in encode
    encode_cmd.append(args[i].encode(util.arg_encoding()))
  File "c:\users\REDACTED\appdata\local\programs\python\python36-32\lib\encodings\cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character '\u2606' in position 30: character maps to <undefined>

#2

Yes, this indeed looks like #2374.


#3

So the fix suggested in #2374 was upgrading to Python 3.6 and using chcp 65001. This is my beet version output.

beets version 1.4.5
Python version 3.6.3
plugins: alternatives, convert, copyartifacts, customfields, embedart, info, inline

Something else I noticed was that my traceback links to cp1252, while the issue rollingstar had was with cp437, which is the default character encoding table for windows command prompt. I’ve used both cmder, powershell, and command prompt, but they all generate the same error. I’d assume that there shouldn’t have been any major changes from 3.6 to 3.6.3 causing this type of issue to reemerge.


#4

So, interestingly enough, if I replace line 213 in convert.py like so

        if six.PY2:
            encode_cmd.append(args[i])
        else:
            encode_cmd.append(args[i])
            #encode_cmd.append(args[i].encode(util.arg_encoding()))

It somehow works. Apparently the util.arg_encoding() function is causing some sort of issue. I don’t really know why python kept defaulting to 1252 when I had the prompt in 65001, but this works as a pseudo-fix for me. I’m assuming that the util.arg_encoding function wasn’t properly picking up the codesheet I was using, resulting in this error. I could run ‘ß’.encode(‘utf-8’) in my python console and it would output a proper byte code without issue.


#5

Hi! Thanks for investigating—if you have actionable evidence, would you mind posting it in the GitHub issue thread for the bug? That way, people working on the problem have only one place to look.