Has something changed about python urllib2 in the latest upd

Posted on
Tue Jun 14, 2022 11:39 am
Wizard Sleeve offline
Posts: 64
Joined: Feb 11, 2008
Location: Berkshire, United Kingdom

Has something changed about python urllib2 in the latest upd

Hi since the latest update none of my devices that I control with a script like this work anymore...

import urllib2

url = 'http://10.0.1.19/rako.cgi?room=17&ch=1&lev=26'
response = urllib2.urlopen(url)
html = response.read()

indigo.server.log(html)

That returns...

Script Error trigger "Studio @ Office @ Hardware @ Main Lights @ Brightness 10" embedded script error:
Script Error No module named 'urllib2'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 1, at top level
ModuleNotFoundError: No module named 'urllib2'

Was working fine before and all I did was run the update

Thanks In advance

Lee

Posted on
Tue Jun 14, 2022 12:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Has something changed about python urllib2 in the latest

Right. urllib2 no longer exists in Python 3.

We recommend using the requests lib, which we install as part of the Indigo install:

Code: Select all
import requests
url = 'http://10.0.1.19/rako.cgi?room=17&ch=1&lev=26'
reply = requests.get(url)
indigo.server.log(reply.text)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 15, 2022 3:30 pm
Wizard Sleeve offline
Posts: 64
Joined: Feb 11, 2008
Location: Berkshire, United Kingdom

Re: Has something changed about python urllib2 in the latest

Thanks that did the trick.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests