2017-12-26, 14:09
I am currently processing some bug reports and faced a unicode-problem in my addon.
I use the xbmcaddon python module and its Addon class to get data and settings for the addon as recommended.
In the code documentation it is stated, that getSetting and getLocalizedString both return unicode strings. This is for Kodi 16 (jarvis), but I did not find one for Kodi 17 (krypton).
First thing I am not sure about:
I use Kodi 17.6, and still use getString probably as a relict from the past. The method getLocalizedString does not seem to exist.
Second thing: I used both getString and getSetting in the same way, but getSetting seems to only return "normal" strings and getString returns unicode strings (which are a different python type).
I checked the variables in the python debugger in Eclipse. The German characters Ä,ä,ö,ü,ß are not standard ASCII.
My solution is to use .decode('utf-8') on all values returned by getSetting that contain user entered strings like directories.
This was no problem until I found out that I forgot the decode on mysql passwords that a user entered in kyrillic.
So my question is:
Is the decode-approach correct or is there another best practice? Or is this just an inaccuracy in the documentation?
I use the xbmcaddon python module and its Addon class to get data and settings for the addon as recommended.
In the code documentation it is stated, that getSetting and getLocalizedString both return unicode strings. This is for Kodi 16 (jarvis), but I did not find one for Kodi 17 (krypton).
First thing I am not sure about:
I use Kodi 17.6, and still use getString probably as a relict from the past. The method getLocalizedString does not seem to exist.
Quote:AttributeError: 'module' object has no attribute 'getLocalizedString'
Second thing: I used both getString and getSetting in the same way, but getSetting seems to only return "normal" strings and getString returns unicode strings (which are a different python type).
I checked the variables in the python debugger in Eclipse. The German characters Ä,ä,ö,ü,ß are not standard ASCII.
python:_Addon = xbmcaddon.Addon(u'service.watchedlist')
_Addon.getSetting("mysql_pass")
str: watchedlistäöüß
utils.getString(30022)
unicode: Gesehen-Änderungen laufend überwachen
My solution is to use .decode('utf-8') on all values returned by getSetting that contain user entered strings like directories.
This was no problem until I found out that I forgot the decode on mysql passwords that a user entered in kyrillic.
So my question is:
Is the decode-approach correct or is there another best practice? Or is this just an inaccuracy in the documentation?