trakt / script.trakt

Trakt.tv movie and TV show scrobbler for Kodi
GNU General Public License v2.0
318 stars 149 forks source link

Proxy scheme error: kodi proxy settings not applied correctly #550

Closed henry-nicolas closed 3 years ago

henry-nicolas commented 3 years ago

Expected Behavior

The trakt plugin should apply the Kodi proxy settings correctly, avoiding the backtrace hereunder. It seems that the proxy url is not build correctly from the KODI parameters. KODI offers 3 main settings, the scheme (http, socks etc...), the hostname of the proxy and the port. Those 3 settings must be combined to build the proxy URL to be used by other Python modules such as urllib3.

Current Behavior

When changing the KODI settings to replace the hostname field with a full URL, the bug is worked around. Ie: change proxy.example.com with http://proxy.example.com:3128 However, that is not a workable solution as it breaks other plugin which are doing the concatenation of the 3 settings correctly (such as Youtube plugin), those plugin then crash on an error building a proxy string that looks like http://http://proxy.example.com:3128:3128

Possible Solution

Check how the proxy settings are passed along to script.module.requests and fix the concatenation of settings.

Steps to Reproduce (for bugs)

  1. Run KODI 19 with script.trakt installed
  2. Configure Kodi to use a proxy, setting the 3 options (scheme to http, hostname of the proxy and the port number).
  3. With a registered trakt account, try scrobbing, rating of movies/episode etc... and watch kodi log file for error

Context

Prevent trakt context menu from working, crashes with below error message.

Your Environment

henry-nicolas commented 3 years ago

Log file for the error:

2021-05-24 11:28:44.838 T:2263    FATAL <general>: [script.trakt] resources.lib.service: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <type 'InvalidURL'>
                                                   Error Contents: (ProxySchemeUnknown('Proxy URL had no scheme, should start with http:// or https://'),)
                                                   Traceback (most recent call last):
                                                     File "/home/kodi/.kodi/addons/script.module.requests/lib/requests/adapters.py", line 412, in send
                                                       conn = self.get_connection(request.url, proxies)
                                                     File "/home/kodi/.kodi/addons/script.module.requests/lib/requests/adapters.py", line 309, in get_connection
                                                       proxy_manager = self.proxy_manager_for(proxy)
                                                     File "/home/kodi/.kodi/addons/script.module.requests/lib/requests/adapters.py", line 193, in proxy_manager_for
                                                       manager = self.proxy_manager[proxy] = proxy_from_url(
                                                     File "/home/kodi/.kodi/addons/script.module.urllib3/lib/urllib3/poolmanager.py", line 536, in proxy_from_url
                                                       return ProxyManager(proxy_url=url, **kw)
                                                     File "/home/kodi/.kodi/addons/script.module.urllib3/lib/urllib3/poolmanager.py", line 480, in __init__
                                                       raise ProxySchemeUnknown(proxy.scheme)
                                                   urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://

                                                   During handling of the above exception, another exception occurred:

                                                   Traceback (most recent call last):
                                                     File "/home/kodi/.kodi/addons/script.trakt/resources/lib/service.py", line 63, in _dispatch
                                                       self.doMarkWatched(data)
                                                     File "/home/kodi/.kodi/addons/script.trakt/resources/lib/service.py", line 309, in doMarkWatched
                                                       result = globals.traktapi.addToHistory(summaryInfo)
                                                     File "/home/kodi/.kodi/addons/script.trakt/resources/lib/traktapi.py", line 244, in addToHistory
                                                       result = Trakt['sync/history'].add(mediaObject)
                                                     File "/home/kodi/.kodi/addons/script.module.trakt/lib/trakt/interfaces/base/__init__.py", line 20, in wrap
                                                       return func(*args, **kwargs)
                                                     File "/home/kodi/.kodi/addons/script.module.trakt/lib/trakt/interfaces/sync/core/mixins.py", line 86, in add
                                                       response = self.http.post(
                                                     File "/home/kodi/.kodi/addons/script.module.trakt/lib/trakt/core/http.py", line 188, in post
                                                       return self.request('POST', path, params, data, **kwargs)
                                                     File "/home/kodi/.kodi/addons/script.module.trakt/lib/trakt/core/http.py", line 121, in request
                                                       return self.send(prepared)
                                                     File "/home/kodi/.kodi/addons/script.module.trakt/lib/trakt/core/http.py", line 142, in send
                                                       response = self.session.send(request, timeout=timeout)
                                                     File "/home/kodi/.kodi/addons/script.module.requests/lib/requests/sessions.py", line 655, in send
                                                       r = adapter.send(request, **kwargs)
                                                     File "/home/kodi/.kodi/addons/script.module.requests/lib/requests/adapters.py", line 414, in send
                                                       raise InvalidURL(e, request=request)
                                                   requests.exceptions.InvalidURL: Proxy URL had no scheme, should start with http:// or https://
                                                   -->End of Python script error report<--
razzeee commented 3 years ago

While this would be a simple change, I'm not sure it's fine to assume the scheme to be either https or http.

https://github.com/trakt/script.trakt/blob/173dd4ac9053b3a61abca92e905418693304201f/resources/lib/kodiUtilities.py#L362

henry-nicolas commented 3 years ago

@Razzeee - I opened a PR for this.

You may want to try to reproduce, the issue being that the settings are unique across Kodi and other plugin (tested with YouTube and also catchuptvandmore) won't accept a kodi setting where the sheme is mentionned in the proxyURL.

Therefore, as-is, it is not possible to have all those plugins working on the same setup with a proxy config. Note that in my PR I prepend a default scheme only if none is defined already.