3

I'm trying to find a way to disable this error logging in my python code. The program seems to actually run fine, the search function just returns a whole buttload of json objects with dozens of attributes each whenever it finds a character that it cant print it will print the thousands of json objects returned to the console.

I wrapped the guilty code (below) in a try block but it hasn't changed anything.

try:
    results = api.search(query)
    print('Station hits: ', len(results['station_hits']), '\nSong hits: ', len(results['song_hits']), '\nArtist hits: ', len(results['artist_hits']), '\nAlbum hits: ', len(results['album_hits'])).encode('ascii', 'ignore')
except UnicodeEncodeError:
    pass

Here is the error that is printed to the console. (Without the buttload of text referenced earlier)

--- Logging error ---
Traceback (most recent call last):
  File "C:\Users\670854\AppData\Local\Programs\Python\Python36-32\lib\logging\__init__.py", line 989, in emit
    stream.write(msg)
  File "C:\Users\670854\AppData\Local\Programs\Python\Python36-32\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 '\u2117' in position 108194: character maps to <undefined>
Call stack:
  File "gpm.py", line 247, in <module>
    main()
  File "gpm.py", line 181, in main
    results = api.search(query)
  File "C:\Users\670854\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gmusicapi\clients\mobileclient.py", line 1806, in search
    res = self._make_call(mobileclient.Search, query, max_results)
  File "C:\Users\670854\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gmusicapi\clients\shared.py", line 84, in _make_call
    return protocol.perform(self.session, self.validate, *args, **kwargs)
  File "C:\Users\670854\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gmusicapi\protocol\shared.py", line 243, in perform
    log.debug(cls.filter_response(parsed_response))
Bellerofont
  • 1,081
  • 18
  • 17
  • 16
Kreg
  • 61
  • 8
  • may be related to: [Why doesn't Python recognize my utf-8 encoded source file?](http://stackoverflow.com/questions/14284269/why-doesnt-python-recognize-my-utf-8-encoded-source-file), and many others, including [UnicodeEncodeError: 'charmap' codec can't encode - character maps to , print function](http://stackoverflow.com/questions/14630288/unicodeencodeerror-charmap-codec-cant-encode-character-maps-to-undefined) – chickity china chinese chicken Jan 20 '17 at 18:36

1 Answers1

-1

Trace-back etc reveals: Can't encode u"\u2117" using cp1252, not surprising, use utf8 instead.

John Machin
  • 81,303
  • 11
  • 141
  • 189
  • 1
    Thanks, but how exactly can I do that? Is this a problem with the terminal im using to run the file or something with the file itself? – Kreg Jan 26 '17 at 19:06