Script urllib2.urlopen not working on Kodi Matrix

i used a script to switch some lights via kodi with this little script:

import urllib2

but now it doesn’t work anymore:

2021-11-15 22:18:42.872 T:2828    DEBUG <general>: CPythonInvoker(8, /home/osmc/ start processing
2021-11-15 22:18:43.063 T:2758    DEBUG <general>: PushCecKeypress - received key fb duration 223
2021-11-15 22:18:43.068 T:2828    DEBUG <general>: -->Python Interpreter Initialized<--
2021-11-15 22:18:43.068 T:2828    DEBUG <general>: 
2021-11-15 22:18:43.068 T:2828    DEBUG <general>: CPythonInvoker(8, /home/osmc/ the source file to load is "/home/osmc/"
2021-11-15 22:18:43.068 T:2828  WARNING <general>: CPythonInvoker(8): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
2021-11-15 22:18:43.069 T:2828    DEBUG <general>: CPythonInvoker(8, /home/osmc/ setting the Python path to /home/osmc:/home/osmc/.kodi/addons/
2021-11-15 22:18:43.070 T:2828    DEBUG <general>: CPythonInvoker(8, /home/osmc/ entering source directory /home/osmc
2021-11-15 22:18:43.459 T:2828    ERROR <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'ModuleNotFoundError'>
                                                   Error Contents: No module named 'urllib2'
                                                   Traceback (most recent call last):
                                                     File "/home/osmc/", line 1, in <module>
                                                       import urllib2
                                                   ModuleNotFoundError: No module named 'urllib2'
                                                   -->End of Python script error report<--
2021-11-15 22:18:43.460 T:2828    DEBUG <general>: onExecutionDone(8, /home/osmc/
2021-11-15 22:18:43.667 T:2828     INFO <general>: Python interpreter stopped

i searched a little bit and it appears that matrix moved to a newer python version but that’s all i got. after that’s it’s way too technical for me.
would be great if anyone could help me out :wink:

best regards


Google search hit this:




import urllib.request

Should work.

Thanks Tom.

works like a charm!
thank you!

1 Like