gmusicapi
gmusicapi copied to clipboard
UnicodeEncodeError with logging when using Mobileclient Search
trafficstars
New error popping up:
--- Logging error ---
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\logging\__init__.py", line 985, in emit
stream.write(msg)
File "C:\Program Files\Python37\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 '\U0001f49b' in position 32828: character maps to <undefined>
Call Stack:
File "C:\Program Files\Python37\lib\site-packages\gmusicapi\clients\mobileclient.py", line 1961, in search
res = self._make_call(mobileclient.Search, query, max_results)
File "C:\Program Files\Python37\lib\site-packages\gmusicapi\clients\mobileclient.py", line 48, in _make_call
return super(Mobileclient, self)._make_call(protocol, *args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\gmusicapi\clients\shared.py", line 90, in _make_call
return protocol.perform(self.session, self.validate, *args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\gmusicapi\protocol\shared.py", line 247, in perform
log.debug(cls.filter_response(parsed_response))
Happens when calling mobileclient.search("test") and the encoding used for the string doesnt seem to affect it.
Hm, this sounds like https://github.com/simon-weber/gmusicapi/issues/632#issuecomment-489285698 again, though I had thought it was fixed. I guess this is during printing to the console rather than the file?
I don't think there's a straightforward way to override the system encoding in this case. The workarounds look pretty hacky:
- have the stream handler read from the file: http://stoken-tips-and-tricks.blogspot.com/2015/02/howto-python-setup-unicode-logging.html
- monkeypatch encode on the logger: https://www.reddit.com/r/learnpython/comments/95uzy2/logging_how_to_define_encoding_of/