One of the things I cannot get working in my Plug-in are the most exotic characters such as åäö. As I’m from Finland and the plug-in contents as well, this is vital. And also some of the videos don’t even play because of the errors caused by this.
File "/Users/xxx/Library/Application Support/Plex/Plex Media Server.app/Contents/Resources/Python/Resources/PMS/MediaXML.py", line 59, in SetAttr<br />
self.root.set(name, value)<br />
File "lxml.etree.pyx", line 641, in lxml.etree._Element.set (src/lxml/lxml.etree.c:9596)<br />
File "apihelpers.pxi", line 416, in lxml.etree._setAttributeValue (src/lxml/lxml.etree.c:31761)<br />
File "apihelpers.pxi", line 1136, in lxml.etree._utf8 (src/lxml/lxml.etree.c:37215)<br />
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes
It seems that the MediaItem is receiving some unacceptable data. This happened when a video title contained some of the aforementioned characters mentioned earlier. For example 'ä' is displayed like this in the ui: 'ä'. Even though I have selected Unicode from the display settings. Plug-ins like YouTube, for instance, do display the characters correctly. I just can't seem to grasp why.
Sorry, I can't help, but Im having similar or exactly the same problems (depending if I read you correctly). Swedish characters are problematic to show in the infoList. If add for example:
dir.AppendItem(DirectoryItem("noje", "Nöje", ""))
... the App doesnt even show in the list. If changed to o from ö then the App shows in the list...
Just so you know, those log lines aren't UTF8 errors. They're framework messages related to localization. You can include strings files for multiple languages in your plug-in. This will allow the plug-in to be automatically localized based on language information provided by Plex (not yet implemented, but will be used within the next few versions). Strings files are JSON dictionaries using key-value pairs, and should be saved in the Strings folder, e.g. /Contents/Strings/en.json. You can then easily localize your plug-in using the _L method defined in PMS.Shorthand, e.g.
from PMS.Shorthand import _L<br />
<br />
localizedString = _L("KeyName")
The framework is logging those lines as it sets the default language to en-us, and your plug-in doesn't include strings for that language.
I have been trying to figure out what's the problem here. I found this googling: [http://www.red-mercury.com/blog/eclectic-t...ery-of-the-day/](http://www.red-mercury.com/blog/eclectic-tech/python-mystery-of-the-day/). It could explain the behavior that I'm experiencing. As the page author states:
So maybe the original site that I'm requesting data from is being read as iso-8559-1 and not utf-8. What made my suspicious is the fact that the site doesn't declare any xml document type, like <?xml version="1.0" encoding="UTF-8"?>. Could this be the reason?
This is how I got it working. I’m pretty sure it’s not the proper way to do it. But at least I get the ui to display some proper characters:
def utf8decode(s):<br />
s = s.encode("iso-8859-1")<br />
return s.decode("utf-8")<br />
<br />
for item in XML.ElementFromURL(PLUGIN_ROOT, True).xpath("//div[@class='foo']"):<br />
item_name = utf8decode(item.xpath("a")[0].text)<br />
...<br />
dir.AppendItem(DirectoryItem(item_id+"$"+item_name, item_name, Utils.EncodeStringToUrlPath(thumb), summary))
So basically first I encode the text to iso-8859-1 and then decode it back to utf-8 in order to be able to append the item. Weird? Well, I think so, too. This is what made me try it out: [http://groups.google.com/group/comp.lang.p...0bca2728df55bc6](http://groups.google.com/group/comp.lang.python/browse_thread/thread/00bca2728df55bc6)
I also tried to play with BeautifulSoup to no avail.
Someone has likely a more elegant solution to this.