Python ctypes import error
#1
Hello,
I am occasionally get error from some addons that uses ctypes import.

generally the error is
 
python:
EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.MemoryError'>
Traceback (most recent call last):
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.skin.helper.service\service.py", line 10, in <module>
from resources.lib.main_service import MainService
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.skin.helper.service\resources\lib\main_service.py", line 15, in <module>
from webservice import WebService
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.skin.helper.service\resources\lib\webservice.py", line 11, in <module>
import cherrypy
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.module.cherrypy\lib\cherrypy\__init__.py", line 76, in <module>
from cherrypy import _cprequest
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.module.cherrypy\lib\cherrypy\_cprequest.py", line 10, in <module>
from cherrypy import _cpreqbody, _cpconfig
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.module.cherrypy\lib\cherrypy\_cpreqbody.py", line 135, in <module>
import cheroot.server
File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\script.module.cherrypy\lib\cheroot\server.py", line 1199, in <module>
from ctypes import windll, WinError
File "S:\Program Files\WindowsApps\XBMCFoundation.Kodi_17.9.110.70_x64__4n2hpmxwrvr6p\system\python\Lib\ctypes\__init__.py", line 552, in <module>
_reset_cache()
File "S:\Program Files\WindowsApps\XBMCFoundation.Kodi_17.9.110.70_x64__4n2hpmxwrvr6p\system\python\Lib\ctypes\__init__.py", line 276, in _reset_cache
CFUNCTYPE(c_int)(lambda: None)
MemoryError

I think the error comes from python itself, because it searches for _reset_cache and seems dont find it or raise an error there. Is that can be fixed?
Reply
#2
Likely needs to be raised with addon authors, UWP does not allow the full suite of python commands because if the sandbox nature of the UWP app environment for addons need to be adjusted for this, and this needs to be done by the addon author.
Reply
#3
(2018-03-04, 14:11)jjd-uk Wrote: Likely needs to be raised with addon authors, UWP does not allow the full suite of python commands because if the sandbox nature of the UWP app environment for addons need to be adjusted for this, and this needs to be done by the addon author.
 Well i could agree with that but what i dont understand here is that just the call "import ctypes" rises the error.
In the code of the addon is never used _reset_cache() function so something to be adjusted. At least i think so.
The python itself rises an error when trying to import ctypes. Isn't that need to be fixed in kodi itself or in the xbox one (UWP) python implementation?
Reply
#4
Does it happen with the Windows desktop version? as if that’s ok so it’s a UWP only problem then there likely nothing we can do within the Kodi code, although I’m not an expert on this so I maybe wrong.
Reply
#5
I dont see errors in desktop version. Errors comes only in XBOX One version.
Well if it can not be fixed in Kodi itself maybe Kodi team should collaborate with Microsoft about this. Since that error is python related (error in import) maybe Microsoft could give a light to the situation.
Reply
#6
Have you tried the UWP app on the desktop? in case you not aware on how to do this see https://kodi.wiki/view/HOW-TO:Install_Ko...tall_on_PC
Reply
#7
Well i tired it now....However what i notice is that UWP version for desktop in Windows Store is version 17.6 not 18.0 Alpha.
However on that version it does not rises any errors from the same plugin. Seems the error is only on XBOX ONE or it is related to alpha version of Kodi used there.
Reply
#8
What is in the Store is NOT the UWP version, as the UWP version is alpha what is in the Store is the version based on the Stable v17.6 desktop version run through the Microsoft Desktop Bridge, so it's just the normal Win32 desktop version in a Store compatible wrapper. That is why I provided the link above explaining how to install the UWP v18 alpha builds that can be downloaded from our mirror servers.

[edit] Download the cer and appx files for same build name and date from http://mirrors.kodi.tv/nightlies/windows/uwp64/master/ and follow instructions linked above
Reply
#9
OK. i see. Now i installed it by the tutorial. On the Desktop machine it rises now the same error like on the XBOX ONE. So then could be a UWP issue.
Well i couldnt test much because Kodi crashes most of the time when i try 18.0 Alpha UWP app but at least it gives the same errors lik eon XBOX.
Reply
#10
Thanks, just wanted to confirm if it was a general UWP issue and not just an issue restricted to the Xbox.
Reply
#11
Also ran into this issue with PlexKodiConnect using Kodi Alpha 3 on Xbox (See https://github.com/croneter/PlexKodiConnect/issues/521). I'm using the Python module watchdog, which imports ctypes and then leads to the dreaded MemoryError. 

I'm a bit confused here: is this issue being addressed on the Kodi side? Or Xbox side? Or do I need to find a workaround?
 
Quote:09:49:43.145 T:7020   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.MemoryError'>
                                            Traceback (most recent call last):
                                              File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\plugin.video.plexkodiconnect\service.py", line 4, in <module>
                                                from resources.lib import service_entry
                                              File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\plugin.video.plexkodiconnect\resources\lib\service_entry.py", line 8, in <module>
                                                from . import utils
                                              File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\plugin.video.plexkodiconnect\resources\lib\utils.py", line 24, in <module>
                                                from . import path_ops
                                              File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\plugin.video.plexkodiconnect\resources\lib\path_ops.py", line 21, in <module>
                                                from .watchdog.utils import unicode_paths
                                              File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\plugin.video.plexkodiconnect\resources\lib\watchdog\utils\__init__.py", line 42, in <module>
                                                import win32stat
                                              File "U:\Users\UserMgr0\AppData\Local\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalState\addons\plugin.video.plexkodiconnect\resources\lib\watchdog\utils\win32stat.py", line 28, in <module>
                                                import ctypes
                                              File "S:\Program Files\WindowsApps\XBMCFoundation.Kodi_17.9.125.70_x64__4n2hpmxwrvr6p\system\python\Lib\ctypes\__init__.py", line 556, in <module>
                                                _reset_cache()
                                              File "S:\Program Files\WindowsApps\XBMCFoundation.Kodi_17.9.125.70_x64__4n2hpmxwrvr6p\system\python\Lib\ctypes\__init__.py", line 276, in _reset_cache
                                                CFUNCTYPE(c_int)(lambda: None)
                                            MemoryError
                                            -->End of Python script error report<--
Reply
#12
There is no way around this issue under UWP... You'll have to limit the plugin for non UWP use or program around the issue using https://github.com/xbmc/xbmc/pull/13806 to detect UWP platforms.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#13
Likely allowing loading random native code would brake the uwp sandbox concept, so is prohibited by MS
Reply
#14
OK, thanks a lot for clarifying! PKC will entirely circumvent a loading of the watchdog module to address this issue.
Reply

Logout Mark Read Team Forum Stats Members Help
Python ctypes import error0