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

ImportError: No module named Cryptodome.Random #665

Closed
4 of 12 tasks
pisek opened this issue Apr 15, 2019 · 8 comments
Closed
4 of 12 tasks

ImportError: No module named Cryptodome.Random #665

pisek opened this issue Apr 15, 2019 · 8 comments

Comments

@pisek
Copy link

pisek commented Apr 15, 2019

I'm submitting a ...

  • bug report
  • feature request
  • support request

General infomration

Prerequisites

  • Are you running the latest version?

Description

Cannot login to netflix or use plugin

Steps to Reproduce

  1. Clean installation of kodi
  2. Install Netflix plugin
  3. Go to Netflix plugin

Expected behavior: Should ask for login credentials or show categories

Actual behavior: An error emerges (more in log) and goes to "File manager"

Context (Environment)

Installation

  • I installed the plugin via zip from the Releases page
  • I´m using the Netflix Repo
  • I´m using a different source (Please tell which)

Operating System

  • Linux (x86/x64)
  • OSX (x86/x64)
  • Windows (x86/x64)
  • Linux (ARM)
  • Android

Additional informatin on the environment

[latest OSMC on rpi2 with latest Kodi 18]

Debug log

2019-04-15 18:10:34.131 T:1686106848 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 Cryptodome.Random
Traceback (most recent call last):
File "/home/osmc/.kodi/addons/plugin.video.netflix/service.py", line 18, in
from resources.lib.MSLHttpRequestHandler import MSLTCPServer
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/MSLHttpRequestHandler.py", line 14, in
from resources.lib.MSLv2 import MSL
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/MSLv2.py", line 34, in
from MSLCrypto import MSLCrypto as MSLHandler
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/MSLCrypto.py", line 8, in
from Cryptodome.Random import get_random_bytes
ImportError: No module named Cryptodome.Random
-->End of Python script error report<--
2019-04-15 18:14:02.485 T:1765798624 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.ValueError'>
Error Contents: No JSON object could be decoded
Traceback (most recent call last):
File "/home/osmc/.kodi/addons/plugin.video.netflix/addon.py", line 33, in
NAVIGATION.router(paramstring=REQUEST_PARAMS)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/utils.py", line 60, in wrapped
result = func(*args, **kwargs)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 123, in router
options = self.before_routing_action(params=params)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/utils.py", line 60, in wrapped
result = func(*args, **kwargs)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 867, in before_routing_action
'method': 'is_logged_in'}))
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 1054, in call_netflix_service
parsed_json = json.loads(data, object_pairs_hook=OrderedDict)
File "/usr/lib/python2.7/json/init.py", line 352, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
-->End of Python script error report<--
2019-04-15 18:14:02.678 T:1765798624 WARNING: CPythonInvoker(3, /home/osmc/.kodi/addons/plugin.video.netflix/addon.py): the python script "/home/osmc/.kodi/addons/plugin.video.netflix/addon.py" has left several classes in memory that we couldn't clean up. The classes include: N9XBMCAddon9xbmcaddon5AddonE
2019-04-15 18:14:02.691 T:1795158752 ERROR: GetDirectory - Error getting plugin://plugin.video.netflix/
2019-04-15 18:14:02.697 T:1916167728 ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.netflix/) failed
2019-04-15 18:14:16.856 T:1533010656 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.ValueError'>
Error Contents: No JSON object could be decoded
Traceback (most recent call last):
File "/home/osmc/.kodi/addons/plugin.video.netflix/addon.py", line 33, in
NAVIGATION.router(paramstring=REQUEST_PARAMS)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/utils.py", line 60, in wrapped
result = func(*args, **kwargs)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 115, in router
'method': 'logout'}))
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 1054, in call_netflix_service
parsed_json = json.loads(data, object_pairs_hook=OrderedDict)
File "/usr/lib/python2.7/json/init.py", line 352, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
-->End of Python script error report<--
2019-04-15 18:14:17.168 T:1533010656 WARNING: CPythonInvoker(4, /home/osmc/.kodi/addons/plugin.video.netflix/addon.py): the python script "/home/osmc/.kodi/addons/plugin.video.netflix/addon.py" has left several classes in memory that we couldn't clean up. The classes include: N9XBMCAddon9xbmcaddon5AddonE
2019-04-15 18:14:25.455 T:1533010656 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.ValueError'>
Error Contents: No JSON object could be decoded
Traceback (most recent call last):
File "/home/osmc/.kodi/addons/plugin.video.netflix/addon.py", line 33, in
NAVIGATION.router(paramstring=REQUEST_PARAMS)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/utils.py", line 60, in wrapped
result = func(*args, **kwargs)
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 119, in router
return self.switch_account()
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 814, in switch_account
self._check_response(self.call_netflix_service({'method': 'logout'}))
File "/home/osmc/.kodi/addons/plugin.video.netflix/resources/lib/Navigation.py", line 1054, in call_netflix_service
parsed_json = json.loads(data, object_pairs_hook=OrderedDict)
File "/usr/lib/python2.7/json/init.py", line 352, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
-->End of Python script error report<--

@jakermx
Copy link

jakermx commented Apr 15, 2019

from Cryptodome.Random import get_random_bytes
ImportError: No module named Cryptodome.Random

install pyCryptodomex to fix it

@jakermx
Copy link

jakermx commented Apr 15, 2019

In order to get our add-ons working correctly, we need to add some additional dependencies and their recommended packages.

sudo apt-get install python-pip python-crypto build-essential -y
sudo apt-get install python-all-dev python-setuptools python-wheel -y
sudo apt-get install python-crypto-dbg python-crypto-doc python-pip-whl -y

Now lets install our Python cryptography dependency.

pip install pycryptodomex

To make sure our add-ons are finding our pycryptodomex module, lets add a symbolic link to the location.

sudo ln -s /usr/lib/python2.7/dist-packages/Crypto /usr/lib/python2.7/dist-packages/Cryptodome

@pisek
Copy link
Author

pisek commented Apr 17, 2019

Works. Thanks.

@pisek pisek closed this as completed Apr 17, 2019
@RoyAnderson
Copy link

Thanks. This fixed the same Netflix install problem I was having with the V18 build on a Vero 4K+. Strange they'd have this issue when they control the total environment.

@pisek pisek changed the title Plugin error - JSON decoding failed (change in netflix api?) ImportError: No module named Cryptodome.Random - how to Apr 25, 2019
@pisek pisek changed the title ImportError: No module named Cryptodome.Random - how to ImportError: No module named Cryptodome.Random Apr 25, 2019
@ThoMagnum ThoMagnum mentioned this issue May 9, 2019
3 tasks
@smartathome
Copy link

I ran into the same issue where I did install the dependency via apt-get... as per instructions of @jakermx. Unfortunately, a new issue popped up where the following module was missing "from Crypto.Util import Padding". Although I was convinced that I had installed the right module. It took me a while to figure out that Kodi uses Python2.7 and not Python3. The installed Cryptodome(x) module for 2.7 does not ship with the Padding.py module. Therefore, download it manually from https://raw.githubusercontent.com/dlitz/pycrypto/7acba5f3a6ff10f1424c309d0d34d2b713233019/lib/Crypto/Util/Padding.py into /usr/lib/python2.7/dist-packages/Crypto/Util. And test from the Python prompt whether "from Crypto.Util import Padding" works.

@SolarPowerEV
Copy link

SolarPowerEV commented Sep 10, 2020

Should someone here have trouble installing the Netflix plugin for KODI 18 on his QNAP HD Station running QTS 4.4.3, this might help:

The following instructions assume that the HD Station’s chroot is based in the same folder as it is the case on my QNAP (which was the standard path after installing HD Station through the App Center):

/share/CACHEDEV1_DATA/.qpkg/HD_Station

It might be in a different folder in your case (I am running a TBS-453DX with a single 1TB SSD from WD RED SA500). During my googling sessions I’ve seen instructions and logfiles based on the premise of the HD Station folder being located for example here: /share/MD0_DATA/.qpkg/HD_Station

So maybe check first, if you can cd or ls your way into the folder
/share/CACHEDEV1_DATA/.qpkg/HD_Station
and if that fails, try to find out where your HD Station is located instead in your QTS. The command
getcfg SHARE_DEF defVolMP -f /etc/config/def_share.info
should help with that.

Now come the steps to install the Crypto package to your HD Station that took me quite some time to figure out:
Log into QNAP command line interface (via ssh or telnet) as admin and then execute the following commands:
cd /share/CACHEDEV1_DATA/.qpkg/HD_Station
chroot .
Now you’re located in the HD station subenvironment as root, which is basically an Ubutunu 18.04 within QNAP’s QTS and gives you access to the usual commands and package managers like apt, pip etc. and can easily execute what CastagnaIT has suggested. In case you’re not very familiar with Linux (like I am), here are the baby steps

apt update (to update the dependencies and repositories in your system)
apt upgrade (you can - and probably should! - skip that command, because it updates everything in your local Ubuntu 18.04 environment, which takes some time. Since I was already frustrated and didn’t care much anymore, I did it nonetheless and couldn’t see any bad consequences (or any difference to be honest except a newer version of the Chrome browser) later when using HD station
apt install build-essential
apt install python-dev
apt install python-pip
apt install python-setuptools
often a message like “it’s already up to date” will be the result. Which is fine, because most packages are probably already included on your HD Station.

Since first using the officially recommended command
pip install --user pycryptodomex

resulted the Crypto package to be installed in the wrong folder /root/.local/lib/python2.7/site-packages/Cryptodome and thus could not be found by the plugin expecting the content to be in /usr/lib/python2.7/dist-packages/Cryptodome
it made it necessary to hack a little by adding a symbolic link and downloading a Padding.py file like described in the posts above in this thread.

But thanks to the helpful comments of CastagnaIT, the author of the Netflix plugin, I was able to correct that mistake and instead install a fitting cryptolibrary in the right location making things easier and cleaner.

Since his first suggestion
apt install python-pycryptodomex

did not work for me, because the package seems to be not known on my QNAP QTS HD-Station Ubuntu subsystem

I used his alternative suggestion
apt install python-pycryptodome

and that worked like a charm. The alternative Crypto library got installed in the right location:
/usr/lib/python2.7/dist-packages/Cryptodome

and there was also a Padding.py to be found in the subfolder /Util

Voilá! You should now be able to use your Netflix plugin without error messages (and without messing around with symbolic links or manually downloaded Padding.py files).

@AnwarKamel
Copy link

Try this:
pip3 install pycryptodomex

@truthelectron
Copy link

I am having the same problem with windows, using pycharm IDE

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

7 participants