01-05-2016 06:26 PM
I would like to invoke a LabVIEW webservice using Python Flask on a RESTful framework, has any one tried doing this?
I found the Ruby Security Client example at Webservice FAQ Whitepapers, but don't fully understand how the Ruby script is called from the LabVIEW project. Has anyone else tried playing with this example?
Thanks for any insight!
01-06-2016 04:32 AM - edited 01-06-2016 04:33 AM
I'm not clear on exactly what you're trying to do - do you mean you want to call a LabVIEW web service from Python? If so, you just need to create an appropriate HTTP request (e.g. GET or POST depending on the configuration of the Web Service VI) to the web service URL with the appropriate parameters/inputs. I'm not a python developer so I don't know the commands to do this but if I was using LabVIEW I'd use the HTTP Client VIs.
If you're using some sort of security on your web service (e.g. HTTP authentication or API keys), then there may be additional steps you need to complete.
01-06-2016 02:06 PM
Good Morning,
I am trying to use a webservice created with python, in a similar way that you create a webservice using LabVIEW in a project. I have a LabVIEW project in which I would like to invoke a webservice, but using python. So I want to be able to have HTTP requests posted to the Python REST client that lies within my project, so that my VI's have access to those posts (and are not required to post for a read request). In the same way data would flow if it were a LabVIEW webservice, but I would have the Python script within the project.
In the ruby example I included, it seems to be doing this, but I can not figure out how LabVIEW is actually calling the ruby script to create the webservice and recieve the HTTP requests. The reason I would prefer to use python, is that I already have a REST client created for this purpose.
Thanks!
01-07-2016 05:39 AM
The example that you linked to - is calling a LabVIEW Web Service from Ruby using the LabVIEW Web Service authentication. It does not call a Ruby script from LabVIEW.
Ok, so let's start by getting our terms clarified:
LabVIEW Web Service - this is a web service created in a LabVIEW project which is hosted by the LabVIEW Application Web Server. The most common usages are to host static content or to create resource VIs which are linked to HTTP URLs to call the VIs.
Web Service - a REST server implementation (in short)
Server - This hosts the web service and responds to incoming HTTP requests.
REST Client - this is an API/application that makes HTTP requests to a Web Service with an API URL, HTTP methods (GET/POST/PUT/DELETE) and additional data.
You say that you have created the Web Service in Python which would act as the Server for incoming requests but then you also talk later about having a Python REST Client - which is what makes the HTTP requests. So which is it?
If your web service is written in Python, and you need the data in LabVIEW - then you will need to use some sort of communication mechanism to transfer the data to LabVIEW. There are some toolkits for using Python with LabVIEW (e.g. LabPython, JKI Python bridge) or you could use another networking protocol like TCP/UDP to transfer the data.
01-08-2016 01:21 PM
I just realized your first statement yesterday unfortunately, I was hoping that LabVIEW was calling the Ruby script.
Sorry for the confusion, I meant a Python REST client. We are also using Python as the webservice though. Currently I am using LabVIEW to poll for changes to the server through the Python REST client using LabVIEW HTTP client vis. I want to no longer poll for changes to the server through the client, but instead have that client push changes to the LabVIEW project. So I was going to attempt to create another webservice using LabVIEW and a Python REST Client for that webservice. Then the client we have can post to the new client. So that LabVIEW would be able to recieve HTTP requests with out the need to poll the client for changes to the server.
I was able to create and use LabVIEW as a webservice and create web resources as my HTTP method VI's, but I found it difficult to find a way to require authentication for requests. Which was more simple to implement when creating a Python REST client. I will look again at using api keys in LabVIEW. I think I will also look into using another networking protocol to transfer the data though.
01-11-2016 04:12 AM
Well you could look at some of the Python toolkits that I mentioned above - you may be able to call your Python REST client from within LabVIEW and then you'd just need to write the code that sends the data from Python back to LabVIEW - I think the toolkits include methods for transferring data between the two.