Script urllib2.urlopen not working on Kodi Matrix

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

import urllib2
urllib2.urlopen('http://ohab3:8080/basicui/CMD?LichtKodi=OFF')

but now it doesn’t work anymore:

2021-11-15 22:18:42.872 T:2828    DEBUG <general>: CPythonInvoker(8, /home/osmc/lightsOFF.py): 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/lightsOFF.py): the source file to load is "/home/osmc/lightsOFF.py"
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/lightsOFF.py): setting the Python path to /home/osmc:/home/osmc/.kodi/addons/plugin.video.youtube/resources/lib/:/home/osmc/.kodi/addons/script.common.plugin.cache/resources/lib/storage_server/:/home/osmc/.kodi/addons/script.module.beautifulsoup4/lib:/home/osmc/.kodi/addons/script.module.certifi/lib:/home/osmc/.kodi/addons/script.module.chardet/lib:/home/osmc/.kodi/addons/script.module.cryptopy/lib:/home/osmc/.kodi/addons/script.module.dateutil/lib:/home/osmc/.kodi/addons/script.module.defusedxml/lib:/home/osmc/.kodi/addons/script.module.future/lib:/home/osmc/.kodi/addons/script.module.html5lib/lib:/home/osmc/.kodi/addons/script.module.idna/lib:/home/osmc/.kodi/addons/script.module.inputstreamhelper/lib:/home/osmc/.kodi/addons/script.module.kodi-six/libs:/home/osmc/.kodi/addons/script.module.libard/lib:/home/osmc/.kodi/addons/script.module.libmediathek4/lib:/usr/share/kodi/addons/script.module.osmccommon/resources/lib/:/usr/share/kodi/addons/script.module.osmcsetting.apfstore/resources/lib/:/usr/share/kodi/addons/script.module.osmcsetting.logging/resources/lib/:/usr/share/kodi/addons/script.module.osmcsetting.networking/resources/lib/:/usr/share/kodi/addons/script.module.osmcsetting.remotes/resources/lib/:/usr/share/kodi/addons/script.module.osmcsetting.services/resources/lib/:/usr/share/kodi/addons/script.module.osmcsetting.updates/resources/lib/:/usr/share/kodi/addons/script.module.pil/lib:/usr/share/kodi/addons/script.module.pycryptodome/lib:/home/osmc/.kodi/addons/script.module.pydes/lib:/home/osmc/.kodi/addons/script.module.requests/lib:/home/osmc/.kodi/addons/script.module.requests-cache/lib:/home/osmc/.kodi/addons/script.module.routing/lib:/home/osmc/.kodi/addons/script.module.six/lib:/home/osmc/.kodi/addons/script.module.soupsieve/lib:/home/osmc/.kodi/addons/script.module.unidecode/lib:/home/osmc/.kodi/addons/script.module.urllib3/lib:/home/osmc/.kodi/addons/script.module.webencodings/lib:/home/osmc/.kodi/addons/script.module.xmltodict/lib:/:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload:/usr/local/lib/python3.7/dist-packages:/usr/lib/python3/dist-packages
2021-11-15 22:18:43.070 T:2828    DEBUG <general>: CPythonInvoker(8, /home/osmc/lightsOFF.py): 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/lightsOFF.py", 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/lightsOFF.py)
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

Hi,

Google search hit this:

Suggests

Changing:

To:

import urllib.request
urllib.request.urlopen('http://ohab3:8080/basicui/CMD?LichtKodi=OFF')

Should work.

Thanks Tom.

works like a charm!
thank you!

1 Like