Heckie75 / kodi-addon-podcast

Subscribe to podcasts in KODI
MIT License
14 stars 3 forks source link

OPML File Fails to Read on Kodi 19.2 #15

Closed stobb3s closed 3 years ago

stobb3s commented 3 years ago

I'm still using the plugin version 2.1.0, which is the latest version in the official repo. When I upgraded Kodi to 19.2, I noticed that my OPML files that were exported from gPodder will no longer open in the plugin. In the log, the error message on my Linux PC is:

2021-10-16 23:21:14.593 T:3091    ERROR <general>: Cannot read opml file /home/user/podcasts.xml

I also tried it on Windows, and the behavior was the same. I traced the issue to the try/expect block that starts on line 381. I removed the try/except to see the error in the log, this was the result:

2021-10-17 09:51:08.971 T:108896   ERROR <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'TypeError'>
                                                   Error Contents: argument 1 must be str, not UnicodeDecodeError
                                                   Traceback (most recent call last):
                                                     File "/home/user/.kodi/addons/plugin.audio.podcasts/addon.py", line 382, in _build_dir_structure
                                                       name, nodes = self._parse_opml(self._open_opml_file(path))
                                                     File "/home/user/.kodi/addons/plugin.audio.podcasts/addon.py", line 366, in _open_opml_file
                                                       return _opml_file.read()
                                                     File "/usr/lib/python3.9/encodings/ascii.py", line 26, in decode
                                                       return codecs.ascii_decode(input, self.errors)[0]
                                                   UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1060: ordinal not in range(128)

From the error message, it appears that this is a file decoding issue. My OPML file is encoded in UTF-8, but Python is assuming that it is ASCII encoding, then fails when a non-ASCII character is detected. No file encoding is specified for the file open() on line 365. When I specify UTF-8 encoding to Python, the file opens correctly:

with open(path, encoding="utf-8") as _opml_file:

Something must have changed in Python for when no encoding is specified between 19.1 and 19.2. The default encoding may also be based on the locale of the user, so it may not be easy to reproduce. I think it is a good idea to specify UTF-8 as a standard encoding. If that fails, then maybe try other encodings. But UTF-8 is a de facto standard for web content these days.

If you need more info or can't reproduce, then I can upload an .opml file. Thanks.

Heckie75 commented 3 years ago

@stobb3s Thanks for this detailed analysis. Actually I found that I've forgot to push the latest version to the repo. I refactored the code , switched to the new settings format and wanted to test it.

Nevertheless, I have changed the code (now in opml_file.py') But I haven't seen the exception in my setup (also v2.1.0)

Maybe you want to try the latest version , i.e. `plugin.audio.podcasts.2.2.1-pre.zip

I'm going to install it in my Kodi setup and test it for a while before pushing it to the repo.

My Kodi version is 19.2 running on Ubuntu 21.04 (x64)

stobb3s commented 3 years ago

I inspected the issue a bit further. I changed the code to print the default locale encoding to the log

import locale
...
...
xbmc.log(f"Prefered Encoding: {locale.getpreferredencoding()}",xbmc.LOGINFO)

Here is the result on Kodi 19.1:

2021-10-17 11:19:12.797 T:121165    INFO <general>: Prefered Encoding: UTF-8

And here is the result on Kodi 19.2:

2021-10-17 11:12:21.824 T:120312    INFO <general>: Prefered Encoding: ANSI_X3.4-1968

Since this is based on locale, that explains why you aren't seeing it. I guess since I have a US locale, Python is now assuming that I want ASCII encoding. Oddly, when I use the Python interpreter provided by my distro, it still shows UTF-8. Not sure why Kodi thinks different. I think I am going to report this to the Kodi devs because most likely many other addons are affected. I will try your updated version and let you know the results. Thanks.

stobb3s commented 3 years ago

Just tested the updated release and the OPML file reads correctly now. Thanks.