Page 2 of 3

Re: HTTPRequest Plugin - v0.1.0

Posted: Tue Aug 22, 2017 7:13 am
by Luca Brasi
hi,

great that you already improved your plugin. Thanks for that.
It will not work for me though as soon as I use cert verification. It's the as when I used Requests directly from a script as posted earlier.

Code: Select all

09:09:09   HTTPRequest: GET https://google.de/
09:09:09      Fehler in Befehl: "HTTPRequest: GET https://google.de/"
09:09:09      Traceback (most recent call last) (0.5.0-rc4):
09:09:09        File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 116, in CallWrapper
09:09:09          return self(*args)
09:09:09        File "C:\ProgramData\EventGhost\plugins\HTTPRequest\__init__.py", line 58, in __call__
09:09:09          stream=False)
09:09:09        File "C:\Program Files (x86)\EventGhost\lib27\site-packages\requests\api.py", line 57, in request
09:09:09          return session.request(method=method, url=url, **kwargs)
09:09:09        File "C:\Program Files (x86)\EventGhost\lib27\site-packages\requests\sessions.py", line 475, in request
09:09:09          resp = self.send(prep, **send_kwargs)
09:09:09        File "C:\Program Files (x86)\EventGhost\lib27\site-packages\requests\sessions.py", line 585, in send
09:09:09          r = adapter.send(request, **kwargs)
09:09:09        File "C:\Program Files (x86)\EventGhost\lib27\site-packages\requests\adapters.py", line 477, in send
09:09:09          raise SSLError(e, request=request)
09:09:09      SSLError: [Errno 2] No such file or directory
Don't you guys get this error?

If I turn off the verification it will work. I'll get this warning though...

Code: Select all

09:10:43   HTTPRequest: GET https://www.google.de/
09:10:43      HTTPRequest: GET https://google.de/
09:10:43         C:\Program Files (x86)\EventGhost\lib27\site-packages\requests\packages\urllib3\connectionpool.py:821: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
09:10:43           InsecureRequestWarning)
09:10:43         C:\Program Files (x86)\EventGhost\lib27\site-packages\requests\packages\urllib3\connectionpool.py:821: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
09:10:43           InsecureRequestWarning)
09:10:43      print results
09:10:43         <Response [200]>
09:10:43         <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="de"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title>
[...........]
</script></div></body></html>

[Edit: ]

I did some digging. This seems to happen because of python is not able to access trusted root CA files on the system. I found some solutions for linux systems but have no clue how python is supposed to work on windows here. Maybe this can be of any help: https://stackoverflow.com/questions/277 ... -directory

Re: HTTPRequest Plugin - v0.1.0

Posted: Tue Aug 22, 2017 2:19 pm
by Boolean263
Luca Brasi wrote:great that you already improved your plugin. Thanks for that.
It will not work for me though as soon as I use cert verification. It's the as when I used Requests directly from a script as posted earlier.
Like you say, the "problem" is with Requests -- though really, Windows is to blame here too. Judging from the link you shared, Requests needs a path to your system's CA certificate files, but Windows doesn't store its certificates in files; it uses the registry.

Were you able to access SSL sites with the original (httplib) version of the HTTPRequest plugin? If so, that might give us a clue as to how to make Requests work, both in general and in this plugin.

Edit: Aha! Look what happens when I actually read the documentation:
By default, Requests bundles a set of root CAs that it trusts, sourced from the Mozilla trust store. However, these are only updated once for each Requests version. This means that if you pin a Requests version your certificates can become extremely out of date.

From Requests version 2.4.0 onwards, Requests will attempt to use certificates from certifi if it is present on the system. This allows for users to update their trusted certificates without having to change the code that runs on their system.

For the sake of security we recommend upgrading certifi frequently!
(emphasis mine, links removed)

So that means we're shipping CA cert bundles with EventGhost, whether we realize it or not, and those certs have gotten out of date for your needs.

Re: HTTPRequest Plugin - v0.1.0

Posted: Tue Aug 22, 2017 9:51 pm
by kgschlosser
the pem file that is included with requests is made by openSSL. but this gives you a means to get rid if the security warning

https://stackoverflow.com/questions/154 ... n-requests

Re: HTTPRequest Plugin - v0.1.0

Posted: Tue Aug 22, 2017 10:17 pm
by Boolean263
kgschlosser wrote:the pem file that is included with requests is made by openSSL. but this gives you a means to get rid if the security warning

https://stackoverflow.com/questions/154 ... n-requests
While it's good to know how to disable SSL verification, that's not a good long-term solution. SSL warnings exist for a reason.

As I noted in my post, the developers of Requests have stated that the pem file that they ship with Requests is liable to become out of date. This is what leads to the errors Luca Brasi is seeing. EventGhost needs to provide a more up-to-date version of the pem file, or else provide instructions for end users to be able to update the file for themselves.

Re: HTTPRequest Plugin - v0.1.0

Posted: Wed Aug 23, 2017 5:45 am
by Pako
Boolean263 wrote:EventGhost needs to provide a more up-to-date version of the pem file, or else provide instructions for end users to be able to update the file for themselves.
Perhaps there is another way. You can consider (try) the use of pycurl instead of Requests.
I was forced to do it (for a similar reason) in the Pushbullet plugin when it suddenly stopped working from day to day. Since then, pycurl has become an integral part of Eventghost installation (at least in version 4).
Of course, I'm not sure it will help in your case.

Pako

Re: HTTPRequest Plugin - v0.1.0

Posted: Wed Aug 23, 2017 3:06 pm
by kgschlosser
IDK if pycurl has been removed form EG 0.5. I would have to go and look. if it has i will add it back again as this is something that should be apart of the EG standard lib.

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Sep 03, 2017 9:33 pm
by Sem;colon
Just for the record, the Webserver Plugin also has the posibillity to send http requests... (Actiin : Send request to another Webserver) :wink:

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 2:50 pm
by Mastiff
I am sorry for being dense, but I am trying to send something with the plug-in. This is the format that is used, with a bit of explanation:
Get list of all devices (AirPlay receivers) on the network, and their details.
HTTP Method GET
URI /devices
Response Headers Content-type: application/json
Content-length: <length of body>
Response Body [{
ÔÇ£IDÔÇØ: ÔÇ£112347690@Living Room AirPort ExpressÔÇØ,
ÔÇ£NameÔÇØ: ÔÇ£Living Room Airport ExpressÔÇØ,
ÔÇ£VolumeÔÇØ: 79,
ÔÇ£StatusÔÇØ: ÔÇ£ConnectedÔÇØ,
ÔÇ£SubstateÔÇØ: ÔÇ£StreamingÔÇØ,
ÔÇ£BufferingÔÇØ: false,
ÔÇ£BufferingPercentÔÇØ: 0
},
{
ÔÇ£IDÔÇØ: ÔÇ£1123124798@Bedroom Bose AirPlay DockÔÇØ,
ÔÇ£NameÔÇØ: ÔÇ£Living Room Airport ExpressÔÇØ,
ÔÇ£VolumeÔÇØ: 39,
ÔÇ£StatusÔÇØ: ÔÇ£ConnectedÔÇØ,ÔÇ£SubstateÔÇØ: ÔÇ£StreamingÔÇØ,
ÔÇ£BufferingÔÇØ: false,
ÔÇ£BufferingPercentÔÇØ: 0
},
{
ÔÇ£IDÔÇØ: ÔÇ£119076520@Kitchen JBL SoundflyÔÇØ,
ÔÇ£NameÔÇØ: ÔÇ£Living Room Airport ExpressÔÇØ,
ÔÇ£VolumeÔÇØ: 71,
ÔÇ£StatusÔÇØ: ÔÇ£ConnectedÔÇØ,
ÔÇ£SubstateÔÇØ: ÔÇ£StreamingÔÇØ,
ÔÇ£BufferingÔÇØ: false,
ÔÇ£BufferingPercentÔÇØ: 0
}]
I have tried to set the plug-in to GET, use 192.168.0.1:56565 as the host/port and devices, or even /devices as the URI, but it keeps throwing back an error:

Code: Select all

15:48:57      Error in Action: "HTTPRequest: Send HTTP request"
15:48:57      Traceback (most recent call last) (1706):
15:48:57        File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
15:48:57          return self(*args)
15:48:57        File "C:\ProgramData\EventGhost\plugins\HTTPRequest\__init__.py", line 54, in __call__
15:48:57          "{}://{}{}".format("https" if ssl else "http", host, uri),
15:48:57      ValueError: zero length field name in format
It's probably an idiot mistake on my part, so I apologize upfront for it! :mrgreen:

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 6:11 pm
by kgschlosser
you need to upgrade to EG 0.5

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 7:53 pm
by Mastiff
I tried that, and now I'm in deep do-do, an important part of my system isn't working! I try to send this through command line:

EventGhost.exe -event Termostat 15 1 24

But this is what comes through:

20:52:15 1.Termostat u"15"

But I'll open a thread in the main setup for that.

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 8:57 pm
by kgschlosser
that has been solved and will be int he next release of EG


but if you surround the payload in double quotes that will get you rolling.

EventGhost.exe -event Termostat "15 1 24"

or if you wanted it to be in a list

EventGhost.exe -event Termostat "[15, 1, 24]"


or if you anted it to all be an event with no payload

EventGhost.exe -event "Termostat 15 1 24"

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 8:59 pm
by Mastiff
Found out why... Turns out that the latest version needs to have the payload inside " ", and then I have to use

Code: Select all

eg.event.payload.split (' ') [0]
instead of just eg.event.payload[0] for the first payload. So back to the scheduled programming: I have now made this code from the example in this thread:

Code: Select all

foo=eg.plugins.HTTPRequest.sendRequest(u'192.168.0.1:56565', uri=u'/devices')
print(foo)
But the return is nothing but 200 (wich means that the request went through without errors), but with none of the info that should be there, like in my post two posts up. Any idea what that happens?

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 9:00 pm
by Mastiff
We seem to have posted at the same time! :mrgreen: Anyway, I hope that you can maybe answer the one I have above too?

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 9:02 pm
by kgschlosser
I think we may depreciate the way it was done in eg 0.4. the reason for that is it always assumes you want a list and you want everything in the list to be a string. and that is not always the case. and would require the user to have to key in a bunch of python code into a script to convert everything. so we may make it more of a convenience by spelling out exactly what they want, as seen in the above examples. this is going to need some refinement and I am going to try to encapsulate both ways into a single mechanism. because as of right now you have no way to specify a dict if you want you will always get a list of strings.

Re: HTTPRequest Plugin - v0.1.0

Posted: Sun Jan 28, 2018 9:05 pm
by kgschlosser
if you want an exact duplicate of what eg 0.4 does then this is the line you need to use

EventGhost.exe -event Termostat "['15', '1', '24']"

as for your next question. i believe that plugin uses the requests module.

Code: Select all

foo=eg.plugins.HTTPRequest.sendRequest(u'192.168.0.1:56565', uri=u'/devices')

content = foo.content

print content