How I can do local request without Domoticz connection in a plugin
Posted: Friday 02 November 2018 20:32
Hello, I m trying to do a simple local request in http to get JSON data.
The request is http://127.0.0.1:8010/api/3E62E09612/lights/
It don't work with domotics internals commands, I can have JSON from other server (on other url, other port) with the same code but impossible for this one.
The code I m using
If I enable debug, I can see
So I know It work, but nothing in onMessage() or other command.
It don't work for this Server, but this simple code work without problem out of domoticz
My machine ATM is
Win 7
Domoticz 4.9700
Python 3.6.4
I have lot of problems.
1 - If I take more recent python version, domoticz don't detect them
2 - If I try to use urllib in domoticz > Crash, it work on external link, but not on local, I know Domoticz have lot of problems with urllib, but I haven't see solution yet.
Do I need to use special python version, domoticz version, or if someone know a workaround ?
The request is http://127.0.0.1:8010/api/3E62E09612/lights/
It don't work with domotics internals commands, I can have JSON from other server (on other url, other port) with the same code but impossible for this one.
The code I m using
Code: Select all
self.Request = Domoticz.Connection(Name="deCONZ_Com", Transport="TCP/IP", Protocol="HTTP" , Address=Parameters["Address"] , Port=Parameters["Port"])
self.Request.Connect()
......
......
sendData = { 'Verb' : 'GET',
'URL' : '/api/3E62E09612/lights/',
'Headers' : { 'Host': Parameters["Address"] + ':' + Parameters["Port"], \
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', \
'User-Agent':'Domoticz' }
}
self.Request.Send(sendData)
Code: Select all
2018-11-02 21:31:13.825 (deCONZ) Received 831 bytes of data
2018-11-02 21:31:13.825 (deCONZ) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 41 63 63 HTTP/1.1.200.OK..Acc
2018-11-02 21:31:13.825 (deCONZ) 65 73 73 2d 43 6f 6e 74 72 6f 6c 2d 41 6c 6c 6f 77 2d 4f 72 ess-Control-Allow-Or
2018-11-02 21:31:13.825 (deCONZ) 69 67 69 6e 3a 20 2a 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 igin:.*..Content-Typ
2018-11-02 21:31:13.825 (deCONZ) 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 6f 6e 3b e:.application/json;
...
...
It don't work for this Server, but this simple code work without problem out of domoticz
Code: Select all
import urllib.request
fp = urllib.request.urlopen("http://127.0.0.1:8010/api/3E62E09612/lights/")
mybytes = fp.read()
mystr = mybytes.decode("utf8")
fp.close()
print(mystr)
My machine ATM is
Win 7
Domoticz 4.9700
Python 3.6.4
I have lot of problems.
1 - If I take more recent python version, domoticz don't detect them
2 - If I try to use urllib in domoticz > Crash, it work on external link, but not on local, I know Domoticz have lot of problems with urllib, but I haven't see solution yet.
Do I need to use special python version, domoticz version, or if someone know a workaround ?