Spanish Character in JSON-RPC output
#1
Hi, a user of my addon reported a problem using the Spanish character in the show name Carnivàle.

BTW, I posted this in the JSON-RPC sub-forum, and was told that JSON uses UTF8, and the database is UTF8. So that leaves me trying to figure out why python thinks the string is ascii. EDIT- which it assumes by default

Here is the query:
Code:
episode_request = {"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":     {"properties": ["season","episode","runtime", "resume","playcount", "tvshowid", "lastplayed", "file"]}, "id": "allTVEpisodes"}

This is the output:
Code:
[{u'tvshowid': 1, u'episode': 5, u'resume': {u'position': 0, u'total': 0}, u'season': 1, u'lastplayed': u'2013-10-01 15:25:54', u'episodeid': 1, u'label': u'1x05. Babylon', u'file': u'C:\\TV Shows\\Carniv\xe0le\\Season1\\Carniv\xe0le.S01E05.mkv', u'playcount': 0, u'runtime': 3600}]

Whenever I try and use 'file' I get this error:
Code:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 115: ordinal not in range(128)

jurrabi's post helped a little. And my current fix is:
Code:
def bodge(name):
    try:
        str(name).lower
        n = name
    except:
        n = name.encode('latin')
       return n

But I get an error when I try to encode to UTF-8, and besides, this doesnt look like a robust solution.

Can anyone advise on a better solution?
Reply
#2
It seems that the character in question is corrupted for some reason - it is hex within a unicode string. This shouldn't normally happen, at least I haven't seen it with Russian titles when queried XBMC library with JSON-RPC.
Reply
#3
Thanks Roman_V_M, that's very helpful. I am going to assume it is a rare problem with the name of this one file.
Reply

Logout Mark Read Team Forum Stats Members Help
Spanish Character in JSON-RPC output0