vially / googlemusic-xbmc

Google Music addon for Kodi
GNU General Public License v3.0
176 stars 48 forks source link

'ascii' codec can't encode character when searching #105

Closed abbaskip closed 5 years ago

abbaskip commented 5 years ago

Loads of search strings return the above error - with varying chars that can't be encoded. Error usually along the lines of: 'ascii' codec can't encode character u'\u3010' in position 0: ordinal not in range(128)

I noticed that the issue is happening during urlencode within urllib.py

To experiment I changed v = quote_plus(str(v))

to v = quote_plus(v.encode("ascii","replace"))

Obviously this isn't ideal as it's changing a Kodi library, when we should be changing what is sent to the library from the addon. This prevents this error, but creates another.

I've found now that when I click on My Library and Albums with this modifield urllib.py I now get an error there instead (and basically the inverse I think): 'ascii' codec can't decode byte 0xe2 in position 15: ordinal not in range(128)

I'm extremely new to Python, but would love to see the solution. I've played around myself but can't work it out. Hopefully somebody much more knowledgeable than me can work it out (even better if it could be explained here!)

abbaskip commented 5 years ago

So I found that searching for: John Williamson

With my urllib.py modification also gives me the decode error:

 File "C:\Program Files\Kodi\system\python\Lib\urllib.py", line 1343, in urlencode
                                                v = quote_plus(v.encode("utf-8","replace"))
                                            UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128)

So it helps with some searches, and not with others. I'm a little confused about the whole thing now - as I'm getting decode and encode errors at the same stage depending on which way I do it.

abbaskip commented 5 years ago

Again playing with urllib.py (which I know isn't the fix for the addon - I'm just hoping one of you smarter guys can then correctly fix the addon thanks to my findings) I have found I can get both searches to return results with error if I replace the code with:

        if isinstance(v,unicode):
            v = quote_plus(v.encode("utf-8","replace"))
        else:
            v = quote_plus(str(v))  
        l.append(k + '=' + v)

HOWEVER, now whenever I load click anything (search results, albums/artists within My library etc) it just takes me to the front screen of the addon.

EDIT:

So all this time, to get it to work I just had to copy what was in the ELSE of the if not doseq:

If statement into both sides of it (basically run it the same regardless) and it works.

Could anyone explain why the urllib.py is running the "is not doseq" when clearly to work it should be running the else?

EDIT2 i worked it out! we need to set doseq to true when calling urlencode! return "?".join([utils.addon_url, urlencode(params, doseq=True)]), li, "true"

I'll submit a pull now

foreverguest commented 5 years ago

Fixed in #106