mbebe / blomqvist

blomqvist
GNU General Public License v3.0
153 stars 56 forks source link

[FIFA plus] Encoding issue makes the addon fail on python2 (kodi 18 or older) #841

Open pitsi opened 2 years ago

pitsi commented 2 years ago

As mentioned in the title, fifa plus fails to launch on kodi 18 because its python2 fails to interpret some character(s) and this comes out in the log

2022-09-26 12:44:53.618 T:140709737121536   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: Non-ASCII character '\xc5' in file /storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py on line 270, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details (helper.py, line 270)
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/main.py", line 3, in <module>
                                                from resources.lib.fifa import Fifa
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/fifa.py", line 9, in <module>
                                                from .helper import Helper
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py", line 270
                                            SyntaxError: Non-ASCII character '\xc5' in file /storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py on line 270, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
                                            -->End of Python script error report<--
2022-09-26 12:44:53.627 T:140709753906944   ERROR: GetDirectory - Error getting plugin://plugin.video.fifaplusbeta/
2022-09-26 12:44:53.631 T:140711372331136   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.fifaplusbeta/) failed

Line 270 does contain some text in non-english characters, which seems to be the days of the week in Polish. I am now trying to find a workaround, I will repost if I succeed. Kodi 19 (or newer) does not have this issue because python3 treats all text as utf8.

---edit

Adding # coding: utf-8 on the first line of plugin.video.fifaplusbeta/resources/lib/helper.py changes the error to this

2022-09-26 13:14:12.407 T:140321496147712   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.ImportError'>
                                            Error Contents: No module named parse
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/main.py", line 3, in <module>
                                                from resources.lib.fifa import Fifa
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/fifa.py", line 9, in <module>
                                                from .helper import Helper
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py", line 11, in <module>
                                                from urllib.parse import quote, unquote
                                            ImportError: No module named parse
                                            -->End of Python script error report<--
2022-09-26 13:14:12.435 T:140321509852928   ERROR: GetDirectory - Error getting plugin://plugin.video.fifaplusbeta/
2022-09-26 13:14:12.451 T:140323080419456   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.fifaplusbeta/) failed
mbebe commented 2 years ago

I will not update addons for KODI 18.9 or older. Please use KODI 19. In this case, you have exceptionally updated addon. plugin.video.fifaplusbeta-0.4.1.zip

pitsi commented 2 years ago

Thanks for the minor update. The addon does open now, but it gets into errors when selecting some menus or entries, e.g. when selecting archive

2022-09-26 20:13:57.973 T:140003110450944   ERROR: /storage/.kodi/addons/script.module.urllib3/lib/urllib3/connectionpool.py:1050: InsecureRequestWarning: Unverified HTTPS request is being made to host 'cxm-api.fifa.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
                                              InsecureRequestWarning,
2022-09-26 20:14:20.783 T:140003068475136   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'requests.exceptions.ConnectTimeout'>
                                            Error Contents: HTTPSConnectionPool(host='cxm-api.fifa.com', port=443): Max retries exceeded with url: /fifaplusweb/api/pages/en/archive (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f550f6643d0>, 'Connection to cxm-api.fifa.com timed out. (connect timeout=15)'))
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/main.py", line 6, in <module>
                                                Fifa()
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/fifa.py", line 383, in __init__
                                                plugin.run()
                                              File "/storage/.kodi/addons/script.module.routing/lib/routing.py", line 130, in run
                                                self._dispatch(self.path)
                                              File "/storage/.kodi/addons/script.module.routing/lib/routing.py", line 141, in _dispatch
                                                view_func(**kwargs)
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/fifa.py", line 52, in listsubmenu
                                                jsdata = helper.request_sess(page, 'get', headers=helper.headers, json=True)
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py", line 158, in request_sess
                                                resp = self.sess.get(url, headers=headers, cookies=cookies, timeout=15, verify=False, allow_redirects=allow)
                                              File "/storage/.kodi/addons/script.module.requests/lib/requests/sessions.py", line 542, in get
                                                return self.request('GET', url, **kwargs)
                                              File "/storage/.kodi/addons/script.module.requests/lib/requests/sessions.py", line 529, in request
                                                resp = self.send(prep, **send_kwargs)
                                              File "/storage/.kodi/addons/script.module.requests/lib/requests/sessions.py", line 645, in send
                                                r = adapter.send(request, **kwargs)
                                              File "/storage/.kodi/addons/script.module.requests/lib/requests/adapters.py", line 507, in send
                                                raise ConnectTimeout(e, request=request)
                                            ConnectTimeout: HTTPSConnectionPool(host='cxm-api.fifa.com', port=443): Max retries exceeded with url: /fifaplusweb/api/pages/en/archive (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f550f6643d0>, 'Connection to cxm-api.fifa.com timed out. (connect timeout=15)'))
                                            -->End of Python script error report<--
2022-09-26 20:14:20.951 T:140003110450944   ERROR: GetDirectory - Error getting plugin://plugin.video.fifaplusbeta/listsubmenu/%2Fen%2Farchive%7Cpage
2022-09-26 20:14:20.963 T:140004679370880   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.fifaplusbeta/listsubmenu/%2Fen%2Farchive%7Cpage) failed

I will investigate it more in kodi 19 and open a new issue if needed.

Please set or add xbmc.python to 3.0.0 as a dependency for any addons that you update so that they no longer appear on the repo as kodi 18 compatible.

pitsi commented 4 months ago

Reopening this 2.5 years later because fifa plus has the same issue after its upgrade to 0.6.

2024-06-02 20:12:18.598 T:139711139297024   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: Non-ASCII character '\xc5' in file /storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py on line 340, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details (helper.py, line 340)
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/main.py", line 3, in <module>
                                                from resources.lib.fifa import Fifa
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/fifa.py", line 9, in <module>
                                                from .helper import Helper
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py", line 340
                                            SyntaxError: Non-ASCII character '\xc5' in file /storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py on line 340, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
                                            -->End of Python script error report<--

Adding this line to the top of helper.py file so force utf8 encoding # -*- coding: UTF-8 -*- gets to this error

2024-06-02 20:16:19.372 T:139711139297024   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.ImportError'>
                                            Error Contents: No module named parse
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/main.py", line 3, in <module>
                                                from resources.lib.fifa import Fifa
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/fifa.py", line 9, in <module>
                                                from .helper import Helper
                                              File "/storage/.kodi/addons/plugin.video.fifaplusbeta/resources/lib/helper.py", line 11, in <module>
                                                from urllib.parse import quote, unquote
                                            ImportError: No module named parse
                                            -->End of Python script error report<--

Truth be told, I have never used the addon for more than testing it in both python2 and python3, because the matches it has have no interest. So, instead of fixing the above, please make it python3 only and call it a day :)