Page 1 of 1

Python Plugin: request from url

Posted: Wednesday 29 November 2017 23:43
by Noudje
I like to get date from an url like www.domain.com?p1=a&p2=b&p3=b. Is that possible with Domoticz.Connection'? I already tried several options with https://github.com/domoticz/domoticz/bl ... es/HTTP.py as an example, but always got the message:
resolve: Host not found (authoritative)
What is the correct procedure to retrieve a response from an url like 'www.domain.com?p1=a&p2=b&p3=b'?

Re: Python Plugin: request from url

Posted: Friday 01 December 2017 5:34
by Dnpwwo
@Noudje,

Have a look at https://github.com/domoticz/domoticz/bl ... es/HTTP.py. It does a get on "/" but you could change it to "?p1=a&p2=b&p3=b" at line 47 and set the base domain via the Hardware page.

Re: Python Plugin: request from url

Posted: Friday 01 December 2017 8:11
by febalci
For the:

Code: Select all

self.httpConn = Domoticz.Connection(Name="HTTP Test", Transport="TCP/IP", Protocol="HTTP", Address=Parameters["Address"], Port=Parameters["Port"])
line, the address parameter should only be the domain name: www.domain.com

For the other lines:

Code: Select all

            sendData = { 'Verb' : 'GET',
                         'URL'  : '/?p1=a&p2=b&p3=b', # or you may have to use '/inde.html?p1=a&p2=b&p3=b'
                         'Headers' : { 'Content-Type': 'text/xml; charset=utf-8', \
                                       'Connection': 'keep-alive', \
                                       'Accept': 'Content-Type: text/html; charset=UTF-8', \
                                       'Host': Parameters["Address"]+":"+Parameters["Port"], \
                                       'User-Agent':'Domoticz/1.0' }
}
Please note that HTTP usage in stable and latest beta is different. This will not work with the stable.

Re: Python Plugin: request from url

Posted: Saturday 02 December 2017 15:34
by Noudje
Thnx for the help!

Meanwhile I found another solution. Now I use urllib to retrieve a csv file from the url.

Re: Python Plugin: request from url

Posted: Sunday 10 December 2017 9:05
by Dnpwwo
@Noudje,

No problem. Just be aware that using urllib will stall the plugin framework while your plugin waits for a response because urllib is synchronous. That won't be a problem if you only run 1 or 2 plugins but can be if you run more than that.

The built in connection solution is asynchronous so will scale much better.