SOAP webservice: Python server and perl client - python

I have created a SOAP service (using spyne). I have used python on the server side. I have a python client that works perfectly fine. But, I want to reuse the output obtained from the server in a perl script (cannot use python).
One possible way would be to call the python client from within perl and capture STDOUT.
But, it would be nice if I could write a simple perl client to get the results. I wrote a simple perl client for SOAP following this, but my code did not print anything.
my $soap = SOAP::Lite->new();
my $service = $soap -> service($URL);
print Dumper($service -> serverFunction($arg1,$arg2));
Here I found a discussion about perl server and python client.
So, is it possible to have a python server and perl client?

Yes, it is possible, but it's SOAP. See the notice from SOAP::Simple:
Let's face it. SOAP is painfull. It's a dumb idea, the only reason you should ever consider using SOAP is if someone holds a gun to your head or pay you a lot of money for it.
If you want to build an API and have both server and client under your control: Try to avoid SOAP whenever possible. Consider switching to a JSON or basic HTTP API.
If you want to keep SOAP, I suggest to try SOAP::Simple, it might work better than SOAP::Lite. There's also the SOAP module, but it's probably too heavy for your usage case.
PS: You might want to include more details (e.g. code you tried) in your question to get a more specific answer.

Related

GRPC: Sending messages from Python to C#, best method?

I am working on a project that just scrapes data from 3 devices (2xserial and 1xssh). I have this part implemented no problem.
I am now heading towards the second part where I need be be able to send the data I need using protobuf to the clients computer where they will receive and display on their own client.
The customer has provided examples of their GRPC servers, and it's written in C#.
Currently, for security reasons, our system uses RedHat 8.3 and I am using a SSH Protocol Library called Paramiko for the SSH part. Paramiko is a Python library. Also the machine I am extracting data from only runs on Linux.
Here are my main questions, and I apologize if I got nowhere.
1.) The developer from the client side provided us with a VM that has a simulator and examples written in C# since their side was written in C#. He says that it's best to use the C# because all examples can be almost re-used as it's all written, etc. While I know it's possible to use C# in Linux these days, I've still have no experience doing so I don't know how complicated/tedious this can get.
2.) I write code in C# and wrap all the python code, which is also something I've never done, but I would be doing this all in RedHat.
3.) I keep it in python because sending protobuf messages works across languages as long as it is sent properly. Also from the client side, I'm not sure if they will need to make adjustments if receiving protobuf messages written in Python(I don't think this is the case because it's just serialized messages, yea?).
Any advice would be appreciated. I am looking to seek more knowledge outside my realm.
Cheers,
Z
If you're happy in Python, I would use option 3. The key thing is to either obtain their .proto schema, or if they've used code-first C# for their server: reverse-engineer the schema (or use tools that generate the schema from code). If you only have C# and don't know how to infer a .proto from that, I can probably help.
That said: if you want to learn some new bits, option 1 (using C# in your system) is also very viable.
IMO option 2 is the worst of all worlds.

Rest API calling python script before returning answer to client

first of all, i apolagise for making such a general question, but it has been really hard to find any useful information on the web.
I would like to create a client side + server side application, which will communicate using a REST api or websockets.
However, my question is the following.
On the server side, after receiving the request from the client,
is it possible to execute a python script, which will return the intended answer, and only then returning that answer to the client?
Let's take an example.
Suppose my client app ask the user which city he is on right now.
Than, the server receives a get request with the name of that city.
Than, the server executes a python script to obtain some information about that city (lets say it searches for the weather).
Only after the script return's the info, can the server return it's answer to the client so it can be rendered.
I hope this is not marked as off topic, as i think this is a relevant general question.
I appreciate your help.
most serious Python Web frameworks have add-on that will do most of the transport / serialisation job.
Django-REST-Framework and Flask-RESTful are the kings in Python language for full stack REST server side applications.
Otherwise, for simple things and few configuration, you could consider Falcon https://falcon.readthedocs.io/en/stable/
On client side, use the "requests" package. http://docs.python-requests.org/en/master/

How can I connect to the apollo graphql-websocket in another programming language?

Currently I am looking into GraphQL Server from Apollo, to replace our current Java implementation. As we also might want to use subscriptions, I try to get some simple server-client proof of concept up and running. I got the subscription part working using the GitHunt example.
As I don't really need or want a UI. For now, I want a simple client to just receive the notifications from the subscription interface. As fas as I could see, this is Websocket. Knowing that, I created a Python script that opens a websocket to the specified host and port (ws://localhost:8090). This results in a bad handshake error.
What way can I go forward? Did someone already create a client, other than the apollo-client? And if so; how do you create the websocket?
I might try using a headless browser like, slimmer js, It supports websockets.
https://github.com/laurentj/slimerjs.
I'm wondering if there is something the python interface just isn't handling that slimer js would be. I'm no websocket expert, so just my 2 cents :)

Python Requests & Django to send a picture from app to server

I would like to do a very simple thing but I kept having trouble to get it work.
I have a client and a server. Both of them have python. The client needs at a certain time in the python code to send a picture to the server and the server is using python to receive the picture, to do some modifications in the picture then save it to disk.
How can I acheive this the easiest way possible? Is Django a good idea?
My problem is that I keep getting an error from the Django server side and it seems it is because I am not managing the cookies.
Can someone give me a sample code for the client and for the server to authenticate then send the file to the server in https?
Also, if you think it is best to use something else than Django, your comments are welcomed :). In fact I managed to get it work very easily with client python and server php but because I have to treat everything in python on the server, I would have prefered not to install apache, php, ... and use only python also to get the picture.
Many thanks for your help,
John.
You don't need Django - a web framework - for this unless you really want to have the features of Django. (Here's a good link. But to sum it up, it would be "a bunch of website stuff".)
You'd probably be best off just using something to transmit data over the network. There are a lot of ways to do this!
If your data is all local (same network) you can use something like ZeroMQ.
If you are not sure if your data is local, or if you know it won't be, you can use HTTP without a server - the Requests library is awesome for this.
In both these scenarios, you'd need to have a "client" and a "server" which you already have a good handle on.

how to implement thin client app with pyqt

Here is what I would like to do, and I want to know how some people with experience in this field do this:
With three POST requests I get from the http server:
widgets and layout
and then app logic (minimal)
data
Or maybe it's better to combine the first two or all three. I'm thinking of using pyqt. I think I can load .ui files. I can parse json data. I just think it would be rather dangerous to pass code over a network to be executed on the client. If someone can hijack the connection, or can change the apps setting to access a bogus server, that is nasty.
I want to do it this way because it keeps all the clients up-to-date. It's sort of like a webapp but simpler because of Qt. Essentially the "thin" app is just a minimal compiled python file that loads data from a server.
How can I do this without introducing security issues on the client? Is https good enough? Is there a way to get pyqt to run in a sandbox of sorts?
PS. I'm not stuck on Qt or python. I do like the concept though. I don't really want to use Java - server or client side.
Your desire to send "app logic" from the server to the client without sending "code" is inherently self-contradictory, though you may not realize that yet -- even if the "logic" you're sending is in some simplified ad-hoc "language" (which you don't even think of as a language;-), to all intents and purposes your Python code will be interpreting that language and thereby execute that code. You may "sandbox" things to some extent, but in the end, that's what you're doing.
To avoid hijackings and other tricks, instead, use HTTPS and validate the server's cert in your client: that will protect you from all the problems you're worrying about (if somebody can edit the app enough to defeat the HTTPS cert validation, they can edit it enough to make it run whatever code they want, without any need to send that code from a server;-).
Once you're using https, having the server send Python modules (in source form if you need to support multiple Python versions on the clients, else bytecode is fine) and the client thereby save them to disk and import / reload them, will be just fine. You'll basically be doing a variant of the classic "plugins architecture" where the "plugins" are in fact being sent from the server (instead of being found on disk in a given location).
Use a web-browser it is a well documented system that does everything you want. It is also relatively fast to create simple graphical applications in a browser. Examples for my reasoning:
The Sage math environment has built their graphical client as an application that runs in a browser, together with a local web-server.
There is the Pyjamas project that compiles Python to Javascript. This is IMHO worth a try.
Edit:
You could try PyPy's sandbox interpreter, as a secure Python interpreter for the code that was transferred over a network.
An then there is the most simple solution: Simply send Python modules over the network, but sign and/or encrypt them. This is the way all Linux distributions work. You store a cryptographic token on the local computer. The server signs/encrypts the code before it sends it, with a matching token. GPG should be able to do it.

Categories