My code to fetch some domoticz json data works perfectly on a standalone basis (using Python 3.6.1)... Here is just a piece of it that illustrates my issue:
Code: Select all
def dzAPICall(APIRequest):
conn = http.client.HTTPConnection(dzIP, dzPort)
conn.request("GET", APIRequest)
response = conn.getresponse()
if response.status == 200:
print("Domoticz API Call '" + APIRequest + "' success")
return json.loads(response.read())
else:
print("Domoticz API Call '" + APIRequest + "' failed")
return False
When I include the same code in a Python plugin within Domoticz's framework (even using today's lastest version 3.7312), adjusted to work within a plugin object:
Code: Select all
def dzAPICall(self, APIRequest):
conn = http.client.HTTPConnection(Parameters["Address"], Parameters["Port"])
conn.request("GET", APIRequest)
response = conn.getresponse()
if response.status == 200:
Domoticz.Debug("Domoticz API Call '" + APIRequest + "' success")
self.onMessage(response.read(), "200", "")
else:
Domoticz.Debug("Domoticz API Call '" + APIRequest + "' failed")
Code: Select all
def onMessage(self, Data, Status, Extra):
Domoticz.Log("onMessage called")
try:
strData = Data.decode("utf-8", "ignore")
Response = json.loads(strData)
except:
Domoticz.Error("Invalid data received!")
return
Thanks!