mopidy / mopidy-soundcloud

Mopidy extension for playing music from SoundCloud
https://mopidy.com/ext/soundcloud/
MIT License
185 stars 59 forks source link

Error when searching text has accented chars. #42

Closed lfcipriani closed 9 years ago

lfcipriani commented 10 years ago

The stacktrace I got is:

Query: "vem chegando o verão"

Server returned error: { message: 'Application error', code: 0, data: { message: 'u\'\xe3\'', traceback: 'Traceback (most recent call last):\n File "/opt/twitter/lib/python2.7/site-packages/mopidy/utils/jsonrpc.py", line 130, in _handle_single_request\n result = self._unwrap_result(result)\n File "/opt/twitter/lib/python2.7/site-packages/mopidy/utils/jsonrpc.py", line 219, in _unwrap_result\n result = result.get()\n File "/opt/twitter/lib/python2.7/site-packages/pykka/future.py", line 299, in get\n exec(\'raise exc_info[0], exc_info[1], exc_info[2]\')\n File "/opt/twitter/lib/python2.7/site-packages/pykka/actor.py", line 200, in _actor_loop\n response = self._handle_receive(message)\n File "/opt/twitter/lib/python2.7/site-packages/pykka/actor.py", line 294, in _handle_receive\n return callee(_message[\'args\'], message[\'kwargs\'])\n File "/opt/twitter/lib/python2.7/site-packages/mopidy/core/library.py", line 195, in search\n return [result for result in pykka.get_all(futures) if result]\n File "/opt/twitter/lib/python2.7/site-packages/pykka/future.py", line 330, in get_all\n return [future.get(timeout=timeout) for future in futures]\n File "/opt/twitter/lib/python2.7/site-packages/pykka/future.py", line 299, in get\n exec(\'raise exc_info[0], exc_info[1], exc_info[2]\')\n File "/opt/twitter/lib/python2.7/site-packages/pykka/actor.py", line 200, in _actor_loop\n response = self._handle_receive(message)\n File "/opt/twitter/lib/python2.7/site-packages/pykka/actor.py", line 294, in _handle_receive\n return callee(_message[\'args\'], message[\'kwargs\'])\n

File "/opt/twitter/lib/python2.7/site-packages/mopidy_soundcloud/library.py", line 177, in search\n tracks=self.backend.remote.search(search_query)\n
File "/opt/twitter/lib/python2.7/site-packages/mopidy_soundcloud/soundcloud.py", line 212, in search\n quote_plus(query)\n

File "/opt/twitter/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1293, in quote_plus\n s = quote(s, safe + \' \')\n File "/opt/twitter/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1288, in quote\n return \'\'.join(map(quoter, s))\nKeyError: u\'\xe3\'\n', type: 'KeyError' } }

rawdlite commented 9 years ago

I do see the same error. This is a search for {"artist": ["Björk"]}

File "/home/tom/projects/audio/mopidy/local/lib/python2.7/site-packages/pykka/actor.py", line 294, in _handle_receive return callee(_message['args'], *_message['kwargs']) File "/home/tom/projects/audio/mopidy/local/lib/python2.7/site-packages/mopidy_soundcloud/library.py", line 177, in search tracks=self.backend.remote.search(search_query) File "/home/tom/projects/audio/mopidy/local/lib/python2.7/site-packages/mopidy_soundcloud/soundcloud.py", line 212, in search quote_plus(query) File "/usr/lib/python2.7/urllib.py", line 1295, in quote_plus return quote(s, safe) File "/usr/lib/python2.7/urllib.py", line 1288, in quote return ''.join(map(quoter, s)) KeyError: u'\xf6'

Unfortunately this breaks searching for the other backends.

rawdlite commented 9 years ago

This patch fixes the error for me.

--- mopidy_soundcloud/library.py.org    2014-12-30 08:14:25.996540248 +0100
+++ mopidy_soundcloud/library.py        2014-12-30 08:02:29.035486060 +0100
@@ -170,7 +170,7 @@
                     tracks=self.backend.remote.resolve_url(search_query)
                 )
         else:
-            search_query = ' '.join(query.values()[0])
+            search_query = ' '.join(query.values()[0]).encode('utf8')
             logger.info('Searching SoundCloud for \'%s\'', search_query)
             return SearchResult(
                 uri='soundcloud:search',

@lfcipriani , if you can verify this i can do a pull request. Also i am not sure whether the search only using the first key value is the best approach.

jodal commented 9 years ago

This was fixed by PR #55.

In related news, with the upcoming Mopidy 1.1, broken search in a single backend should no longer break search for other backends.