rest - Add variable to URL in python for Hue lights -
i know can shorten down length of python api call hue using variable cant figure out format or proper term find answer in stackoverflow. learn how hide auth token practice better security , add variable multiple lights may add in future. believe need multiple variables within url. please appreciated.
import requests url = "http://192.168.98.233/api/cjk7782cabrguggxutlt8dwwnk516ilhmhzhwflq/lights/{}/state".format(1) url2= "http://192.168.98.233/api/cjk7782cabrguggxutlt8dwwnk516ilhmhzhwflq/lights/{}/state".format(2) url3= "http://192.168.98.233/api/cjk7782cabrguggxutlt8dwwnk516ilhmhzhwflq/lights/{}/state".format(3) payload = " {\"on\":false}" headers = { 'content-type': "application/json", 'cache-control': "no-cache" } r = requests.put(url, data=payload, headers=headers) r2 = requests.put(url2, data=payload, headers=headers) r3 = requests.put(url3, data=payload, headers=headers) print(r.text) print(r2.text) print(r3.text)
like :
import requests payload = " {\"on\":false}" headers = { 'content-type': "application/json", 'cache-control': "no-cache" } in range(1, 4) : url = "http://192.168.98.233/api/cjk7782cabrguggxutlt8dwwnk516ilhmhzhwflq/lights/{}/state".format(i) r = requests.put(url, data=payload, headers=headers) print(r.text)
Comments
Post a Comment