HTTPRequest Plugin - v0.1.0

Questions and comments specific to a particular plugin should go here.
User avatar
Luca Brasi
Experienced User
Posts: 262
Joined: Sat Oct 11, 2008 12:39 pm

Re: HTTPRequest Plugin - v0.1.0

Post by Luca Brasi » Tue Aug 22, 2017 7:13 am

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
Win10 x64 Prof. / Eventghost latest / MCE Plugin / MCE RC6 Receiver / Logitech Harmony Hub / MediaPortal / kodi

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: HTTPRequest Plugin - v0.1.0

Post by Boolean263 » Tue Aug 22, 2017 2:19 pm

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.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
kgschlosser
Site Admin
Posts: 3402
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: HTTPRequest Plugin - v0.1.0

Post by kgschlosser » Tue Aug 22, 2017 9:51 pm

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
If you like the work I have been doing then feel free to Image

User avatar
Boolean263
Plugin Developer
Posts: 81
Joined: Sat Aug 12, 2017 7:52 pm
Location: Ottawa, Canada
Contact:

Re: HTTPRequest Plugin - v0.1.0

Post by Boolean263 » Tue Aug 22, 2017 10:17 pm

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.
Windows 10 Home, version 1703, build 15063.540 · EventGhost 0.5.0-rc4 · wxPython 3.0.2.0
Python programmer for fun and profit. Dabbler in EventGhost plugin writing. Wiki gardener. General geek.

User avatar
Pako
Plugin Developer
Posts: 2285
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: HTTPRequest Plugin - v0.1.0

Post by Pako » Wed Aug 23, 2017 5:45 am

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

User avatar
kgschlosser
Site Admin
Posts: 3402
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: HTTPRequest Plugin - v0.1.0

Post by kgschlosser » Wed Aug 23, 2017 3:06 pm

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.
If you like the work I have been doing then feel free to Image

Sem;colon
Experienced User
Posts: 588
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: HTTPRequest Plugin - v0.1.0

Post by Sem;colon » Sun Sep 03, 2017 9:33 pm

Just for the record, the Webserver Plugin also has the posibillity to send http requests... (Actiin : Send request to another Webserver) :wink:

Mastiff
Experienced User
Posts: 828
Joined: Thu May 03, 2012 10:43 am

Re: HTTPRequest Plugin - v0.1.0

Post by Mastiff » Sun Jan 28, 2018 2:50 pm

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:

User avatar
kgschlosser
Site Admin
Posts: 3402
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: HTTPRequest Plugin - v0.1.0

Post by kgschlosser » Sun Jan 28, 2018 6:11 pm

you need to upgrade to EG 0.5
If you like the work I have been doing then feel free to Image

Mastiff
Experienced User
Posts: 828
Joined: Thu May 03, 2012 10:43 am

Re: HTTPRequest Plugin - v0.1.0

Post by Mastiff » Sun Jan 28, 2018 7:53 pm

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.

User avatar
kgschlosser
Site Admin
Posts: 3402
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: HTTPRequest Plugin - v0.1.0

Post by kgschlosser » Sun Jan 28, 2018 8:57 pm

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"
If you like the work I have been doing then feel free to Image

Mastiff
Experienced User
Posts: 828
Joined: Thu May 03, 2012 10:43 am

Re: HTTPRequest Plugin - v0.1.0

Post by Mastiff » Sun Jan 28, 2018 8:59 pm

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?

Mastiff
Experienced User
Posts: 828
Joined: Thu May 03, 2012 10:43 am

Re: HTTPRequest Plugin - v0.1.0

Post by Mastiff » Sun Jan 28, 2018 9:00 pm

We seem to have posted at the same time! :mrgreen: Anyway, I hope that you can maybe answer the one I have above too?

User avatar
kgschlosser
Site Admin
Posts: 3402
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: HTTPRequest Plugin - v0.1.0

Post by kgschlosser » Sun Jan 28, 2018 9:02 pm

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.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3402
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: HTTPRequest Plugin - v0.1.0

Post by kgschlosser » Sun Jan 28, 2018 9:05 pm

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
If you like the work I have been doing then feel free to Image

Post Reply