0

I have had a working program to control my Hue lights for a while, and have recently transferred to a new PC. I went to get it setup, and I received a few errors that I can't work out the reason why they are happening, as the code worked perfectly fine on my old machine.

My Code:

f = open("first.json", "r")
data = json.loads(f.read())
f.close()

login = [index["username"] for index in data]
bridge_ip = [index["bridge_ip"] for index in data]

login = ",".join(login)
bridge_ip = ",".join(bridge_ip)

get_address = "https://%s/api/%s/lights" % (bridge_ip, login)

r_lights = requests.get(get_address)

Errors:

Traceback (most recent call last):
File "C:\Users\Andrew\Desktop\HueProgram\huepy.py", line 69, in <module>
r_lights = requests.get(get_address)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\adapters.py", line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='192.168.1.102', port=443): Max retries exceeded with url: /api/Usba0ripFRGZvGIuhLdFEtnHZBLG-NFhpIEeZ7-B/lights (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x040D89B0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
Dorothy
  • 61
  • 4
  • 11
  • are you sure that is the correct port? – Netwave Feb 15 '17 at 10:04
  • Yes it should be. How would I specify the port with requests? There is one other possible port, but I cannot get it to change, it will only do it for 443. – Dorothy Feb 15 '17 at 10:26
  • You specify the port in the URL, instead of `https://%s/api/%s/lights` you would use `https://%s:/api/%s/lights` or `https://%s:%d/api/%s/lights` with a `(bridge_ip, bridge_port, login)` tuple – Ian Stapleton Cordasco Feb 15 '17 at 13:16
  • You can test the URL by putting into your browser: `https://192.168.1.102/api/Usba0ripFRGZvGIuhLdFEtnHZBLG-NFhpIEeZ7-B/lights` – Stephen Rauch Feb 15 '17 at 20:05
  • Found the issue, was using 'HTTPS' rather than 'HTTP'. Problem solved. – Dorothy Feb 15 '17 at 22:03

0 Answers0