Can't connect to api website with default connection method
Posted: Friday 20 March 2020 17:34
I'm trying to create my first plugin. I got to manage to authenticate to the api url. I retrieve the cookie, but now I'm struggeling on how to pass the cookie to the api url. If I try it with liburl I can manage to read from the api, but not if I use the default connection method.
I got the following code:
Then I got a 400 error code.
If I use liburl code:
This works, and I got the data I want from the api.
I dont understand why it's not working with the default connection methode for plugins.
Anyone an idea?
I got the following code:
Code: Select all
sendData = {'Verb' : 'GET',
'URL' : '/api/s/default/stat/sta/',
'Headers' : {
'Cookie': self.cookie, \
'Host': Parameters["Address"]+":"+Parameters["Port"]
}
}
Domoticz.Log("RequestDetails sendData = "+str(sendData))
self.unifiConn.Send(sendData)
If I use liburl code:
Code: Select all
url = "https://"+Parameters["Address"]+":"+Parameters["Port"]+"/api/s/default/stat/sta/"
reqapi = urllib.request.Request(url,headers={'Cookie':self.cookie})
responseapi = urllib.request.urlopen(reqapi)
test = responseapi.read().decode('utf-8', 'ignore')
Domoticz.Log("API Response = " +test)
I dont understand why it's not working with the default connection methode for plugins.
Anyone an idea?