Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin no longer works due to urllib2 errors on Ubuntu #14

Closed
bbogart opened this issue Jan 20, 2017 · 24 comments
Closed

Plugin no longer works due to urllib2 errors on Ubuntu #14

bbogart opened this issue Jan 20, 2017 · 24 comments

Comments

@bbogart
Copy link

bbogart commented Jan 20, 2017

I can no longer use YouTube 5.3.6 on Kodi 16.1 using Ubuntu 16.04.1 (up to date as of today). Videos -> Add-ons -> YouTube leads to the following error:

18:20:19 T:2833365824  NOTICE: [plugin.video.youtube] Running: YouTube (5.3.6) on Jarvis (16.1) with Python 2.7.12
18:20:19 T:2833365824   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'urllib2.URLError'>
                                            Error Contents: <urlopen error [Errno 0] Error>
                                            Traceback (most recent call last):
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/default.py", line 7, in <module>
                                                runner.run(__provider__)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/kodion/runner.py", line 32, in run
                                                __RUNNER__.run(provider, context)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/kodion/impl/xbmc/xbmc_runner.py", line 23, in run
                                                results = provider.navigate(context)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/kodion/abstract_provider.py", line 93, in navigate
                                                result = method(context, re_match)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/kodion/abstract_provider.py", line 127, in _internal_root
                                                return self.on_root(context, re_match)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/youtube/provider.py", line 537, in on_root
                                                self.get_client(context)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/youtube/provider.py", line 150, in get_client
                                                YouTube(language=language, config=youtube_config).refresh_token(refresh_tokens[1])
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/youtube/client/login_client.py", line 116, in refresh_token
                                                result = requests.post(url, data=post_data, headers=headers, verify=False)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/kodion/simple_requests/api.py", line 194, in post
                                                return _request('POST', url, data=data, json=json, **kwargs)
                                              File "/home/bbogart/.kodi/addons/plugin.video.youtube/resources/lib/kodion/simple_requests/api.py", line 165, in _request
                                                response = opener.open(request)
                                              File "/usr/lib/python2.7/urllib2.py", line 429, in open
                                                response = self._open(req, data)
                                              File "/usr/lib/python2.7/urllib2.py", line 447, in _open
                                                '_open', req)
                                              File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
                                                result = func(*args)
                                              File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
                                                context=self._context)
                                              File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
                                                raise URLError(err)
                                            URLError: <urlopen error [Errno 0] Error>
                                            -->End of Python script error report<--
18:20:19 T:2953627712   ERROR: GetDirectory - Error getting plugin://plugin.video.youtube/
18:20:19 T:2953627712   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.youtube/) failed
18:21:19 T:2507303744  NOTICE: ES: Client  from 192.168.0.111 timed out

Uninstalling and reinstalling did not change anything.

@noam09
Copy link

noam09 commented Jan 20, 2017

Hey @bbogart, what happens if you pip uninstall pyOpenSSL? Make sure to restart Kodi after the removal. When I was experiencing this issue, removing pip's pyOpenSSL actually solved the issue. The problem was I still needed pip's version as well since the Xenial package was still on 0.15.1.

@bbogart
Copy link
Author

bbogart commented Jan 21, 2017

@noam09 I don't recall ever installing pyOpenSSL. The following indicates to me that I have a packaged version,

$pip uninstall pyOpenSSL
Not uninstalling pyopenssl at /usr/lib/python2.7/dist-packages, outside environment /usr

but I can't find any such package installed:

$ dpkg -l pyOpenSSL
dpkg-query: no packages found matching pyOpenSSL

pip does see pyOpenSSL installed:

$ pip list | grep SSL
pyOpenSSL (0.15.1)

@artstar-es
Copy link

artstar-es commented Jan 21, 2017

bbogart, I uninstalled it using sudo -H pip uninstall pyOpenSSL

Problem solved on my Kodi box (running Linux Mint 18 Sarah).

@kylegordon
Copy link

Can confirm, sudo pip uninstall pyOpenSSL fixes this issue on a recently updated Ubuntu 16.04.1 LTS install

11:04:27 T:140511798335232 NOTICE: [plugin.video.youtube] Running: YouTube (5.3.7) on Jarvis (Kodi-16.1) with Python 2.7.12

@noam09
Copy link

noam09 commented Jan 21, 2017

@bbogart, pip show pyOpenSSL should show you where the package is installed. This will help to determine whether it is installed in your user directory or a system-wide directory. @artstar-es's approach may also be the answer.
If removing pip's package solves the issue for you, great. If it doesn't, upgrading pyOpenSSL may be the solution, since I see you have 0.15.1 installed. Latest version is 16.2.0.

@artstar-es
Copy link

@noam09, I'm not sure how successful an upgrade would be if it isn't part of the usual Ubuntu aptitude upgrade rollout. I've experimented with it on my Mint 18 box and it fails to compile (setuptools is installed).

Safest approach would be to just delete it for the moment until another official Python update comes through for Ubuntu.

@bbogart
Copy link
Author

bbogart commented Jan 22, 2017

@noam09, @artstar-es:

Home directory flag does not change anything:

$ sudo -H pip uninstall pyOpenSSL
Not uninstalling pyopenssl at /usr/lib/python2.7/dist-packages, outside environment /usr

pyOpenSSL is indeed installed in /usr/lib/python2.7/dist-packages:

$ pip show pyOpenSSL
---
Metadata-Version: 1.1
Name: pyOpenSSL
Version: 0.15.1
Summary: Python wrapper module around the OpenSSL library
Home-page: https://github.com/pyca/pyopenssl
Author: Jean-Paul Calderone
Author-email: exarkun@twistedmatrix.com
License: APL2
Location: /usr/lib/python2.7/dist-packages
Requires: cryptography, six
Classifiers:
  Development Status :: 6 - Mature
  Intended Audience :: Developers
  License :: OSI Approved :: Apache Software License
  Operating System :: MacOS :: MacOS X
  Operating System :: Microsoft :: Windows
  Operating System :: POSIX
  Programming Language :: Python :: 2
  Programming Language :: Python :: 3
  Programming Language :: Python :: 2.6
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3.2
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: Implementation :: CPython
  Programming Language :: Python :: Implementation :: PyPy
  Topic :: Security :: Cryptography
  Topic :: Software Development :: Libraries :: Python Modules
  Topic :: System :: Networking

I manually removed both pyOpenSSL-0.15.1.egg-info and OpenSSL from /usr/lib/python2.7/dist-packages and now its back to working.

I'm not sure how things got to this state, I did not even have pip installed on this machine until I started debugging this issue.

@bbogart bbogart closed this as completed Jan 22, 2017
@artstar-es
Copy link

It must have been a recent Python update, I suspect. Hopefully the next update for Ubuntu distros will resolve that.

@FulesZacsko
Copy link

Hi guys,

I have the same problem in Youtube and in Tunein addons. Phyton... I try each solution what U wrote, but not working. :(

@guss77
Copy link

guss77 commented Jan 31, 2017

On Ubuntu 16.10 the following solves this problem for me:

  1. Log in to the user where you run Kodi
  2. rm -rf .local/lib/python2.7/ (make sure you aren't using local python packages for other things - in my case this account is only used for Kodi)
  3. pip install --user cryptography
  4. pip install --user pyopenssl

I'm not sure you need both cryptography > 1.7 and pyOpenSSL > 16.2 - just upgrading the latter may be enough, but its probably a good idea to do both. Ubuntu 16.10 bunles cryptography 1.5 and pyOpenSSL 16.1 - which together exhibit this problem. I don't think its a bug in the plugin - I've seen this problem with other software as well.

@noam09
Copy link

noam09 commented Jan 31, 2017

It's definitely not a bug in the plugin itself. Before finding a fix for my system, the same issue occurred when attempting to use the SoundCloud plugin and others as well. Same method, same error.

@FulesZacsko
Copy link

Hi I use Samba on Ubuntu 16.04, so that use python. No solution for me at now... Tried 16.10 Ubuntu too. Kodi is last stable, but I think something went wrong in update... that problem come out after one upgrade...

@guss77
Copy link

guss77 commented Feb 1, 2017

@FulesZacdko - samba is a system service so you should be able to upgrade the Python libraries for the user running Kodi without affecting samba - see my instructions above.

@FulesZacsko
Copy link

@guss77 Working!, thank you!

@Rudd-O
Copy link

Rudd-O commented Feb 3, 2017

Latest jdf76 on Fedora 25 with Kodi Krypton still has the problem, whether it is with pyOpenSSL 16 (stock) or upgraded to pyOpenSSL 17. See:

04:18:52.369 T:140452527331072  NOTICE: Previous line repeats 1 times.
04:18:52.369 T:140452527331072   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'urllib2.URLError'>
                                            Error Contents: <urlopen error [Errno 0] Error>
                                            Traceback (most recent call last):
                                              File "/home/user/.kodi/addons/plugin.video.youtube/default.py", line 7, in <module>
                                                runner.run(__provider__)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/runner.py", line 32, in run
                                                __RUNNER__.run(provider, context)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/impl/xbmc/xbmc_runner.py", line 23, in run
                                                results = provider.navigate(context)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/abstract_provider.py", line 93, in navigate
                                                result = method(context, re_match)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/abstract_provider.py", line 225, in _internal_search
                                                return self.on_search(query, context, re_match)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/youtube/provider.py", line 481, in on_search
                                                page_token=page_token)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/utils/function_cache.py", line 107, in get
                                                cached_data = partial_func()
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/youtube/client/youtube.py", line 488, in search
                                                return self._perform_v3_request(method='GET', path='search', params=params, quota_optimized=False)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/youtube/client/youtube.py", line 615, in _perform_v3_request
                                                result = requests.get(_url, params=_params, headers=_headers, verify=False, allow_redirects=allow_redirects)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/simple_requests/api.py", line 189, in get
                                                return _request('GET', url, **kwargs)
                                              File "/home/user/.kodi/addons/plugin.video.youtube/resources/lib/kodion/simple_requests/api.py", line 165, in _request
                                                response = opener.open(request)
                                              File "/usr/lib64/python2.7/urllib2.py", line 429, in open
                                                response = self._open(req, data)
                                              File "/usr/lib64/python2.7/urllib2.py", line 447, in _open
                                                '_open', req)
                                              File "/usr/lib64/python2.7/urllib2.py", line 407, in _call_chain
                                                result = func(*args)
                                              File "/usr/lib64/python2.7/urllib2.py", line 1243, in https_open
                                                context=self._context)
                                              File "/usr/lib64/python2.7/urllib2.py", line 1200, in do_open
                                                raise URLError(err)
                                            URLError: <urlopen error [Errno 0] Error>
                                            -->End of Python script error report<--
04:18:52.415 T:140456472424128   ERROR: GetDirectory - Error getting plugin://plugin.video.youtube/kodion/search/query/?q=techmoan
04:18:52.415 T:140456472424128   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.youtube/kodion/search/query/?q=techmoan) failed
04:18:52.443 T:140452527331072  NOTICE: [plugin.video.youtube] Running: YouTube (5.3.8) on Krypton (Kodi-17.0) with Python 2.7.13

I can confirm the pyOpenSSL version being used, with a bit of hacking I did right where the exception is being fired:

[root@machine plugin.video.youtube]# cat /tmp/shit 
/usr/lib/python2.7/site-packages/OpenSSL/__init__.pyo
[root@machine plugin.video.youtube]# rpm -qf /usr/lib/python2.7/site-packages/OpenSSL/__init__.pyo
python2-pyOpenSSL-16.2.0-2.fc25.noarch

@Rudd-O
Copy link

Rudd-O commented Feb 3, 2017

Please reopen this bug. This is still a problem with most Linux systems out there, and it ought to be resolved so that we can use the addon.

Related: pyca/pyopenssl#542

@Rudd-O
Copy link

Rudd-O commented Feb 3, 2017

After hours of struggling, I got the mufuggen fix:

diff --git a/resources/lib/kodion/simple_requests/api.py b/resources/lib/kodion/simple_requests/api.py
index 782d776..aa0a0f4 100755
--- a/resources/lib/kodion/simple_requests/api.py
+++ b/resources/lib/kodion/simple_requests/api.py
@@ -1,5 +1,7 @@
 __author__ = 'bromix'
 
+import OpenSSL
+
 import urllib
 import urllib2
 from StringIO import StringIO

That's right — just importing the OpenSSL module before importing urllib* fixes it all. No need to downgrade anything. Just do this and that's it. But do it on every module that imports urllib*.

@Rudd-O
Copy link

Rudd-O commented Feb 3, 2017

Referencing parent project: Kolifanes/plugin.video.youtube#131

@anxdpanic
Copy link
Collaborator

import OpenSSL does not work in my windows environment, the resolution that seems to have worked for all cases I've participated in was "pip install pyopenssl==16.2.0" and only affects linux environments with pyopenssl 16.1.0 from what I have seen.

@anxdpanic
Copy link
Collaborator

anxdpanic commented Feb 26, 2017

@Rudd-O, apologize I mis-read originally.

In order to try to resolve this fully I have replaced the add-on's requests module with script.module.requests (#28) in the current master. Any feedback or confirmation on resolution is appreciated.

Zip including the change: https://github.com/jdf76/plugin.video.youtube/releases/download/5.3.11-alpha/plugin.video.youtube-5.3.11.alpha2.zip

@lukasmrtvy
Copy link

sudo pip install --upgrade pyOpenSSL

.. did the trick

@marksev1
Copy link

What about if i just "pip install --upgrade pyOpenSSL" will that not do the trick?

@Rudd-O
Copy link

Rudd-O commented Jun 23, 2017 via email

@marksev1
Copy link

so now i should pip uninstall it :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants