Send HTTP request with GWT-RPC call via Python - python

I need to initiate an action on server via sending the HTTP request with GWT-RPC call in body section. I'm completely new in GWT subject so please forgive my lack of knowledge. In Java I was able to perform this action via sending HTTP POST request with proper headers and GWT-RPC in body so I tried to do the same in Python with requests library.
Unfortunately, when sending GWT-RPC call I got response:
//EX[2,1,["com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533","This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version between 5 and 7 )"],0,7]
I read few topics:
Manually generating x-gwt-rpc from Python,
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException
and as I understood there's no way to send the GWT-RPC call from other platform than Java without some additionall effort. Please correct me and advise if I'm wrong.

Related

How to read from json-stream API endpoint in Python?

I am contacting an API endpoint, which requires you send an "Accept" parameter in the header, the value of which should be "application/x-json-stream", "text/event-stream".
If I don't add this to the header I get a 406 response.
If I do it seems like the output in the Python console is redirected somewhere. No commands in the console lead to new output anymore.
I am using the requests library and its get method. The endpoint is supposed to be some stream of information, perhaps it is something akin to a websocket.
The endpoint is here.

Implementing WebSockets with Sony's Audio Control API in Python

Sony's website provided a example to use WebSockets to works with their api in Node.js
https://developer.sony.com/develop/audio-control-api/get-started/websocket-example#tutorial-step-3
it worked fine for me. But when i was trying to implement it in Python, it does not seems to work
i use websocket_client
import websocket
ws = websocket.WebSocket()
ws.connect("ws://192.168.0.34:54480/sony/avContent",sslopt={"cert_reqs": ssl.CERT_NONE})
gives
websocket._exceptions.WebSocketBadStatusException: Handshake status 403 Forbidden
but in their example code, there is not any kinds of authrization or authentication
I recently had the same problem. Here is what I found out:
Normal HTTP responses can contain Access-Control-Allow-Origin headers to explicitly allow other websites to request data. Otherwise, web browsers block such "cross-origin" requests, because the user could be logged in there for example.
This "same-origin-policy" apparently does not apply to WebSockets and the handshakes can't have these headers. Therefore any website could connect to your Sony device. You probably wouldn't want some website to set your speaker/receiver volume to 100% or maybe upload a defective firmware, right?
That's why the audio control API checks the Origin header of the handshake. It always contains the website the request is coming from.
The Python WebSocket client you use assumes http://192.168.0.34:54480/sony/avContent as the origin by default in your case. However, it seems that the API ignores the content of the Origin header and just checks whether it's there.
The WebSocket#connect method has a parameter named suppress_origin which can be used to exclude the Origin header.
TL;DR
The Sony audio control API doesn't accept WebSocket handshakes that contain an Origin header.
You can fix it like this:
ws.connect("ws://192.168.0.34:54480/sony/avContent",
sslopt={"cert_reqs": ssl.CERT_NONE},
suppress_origin=True)

How to transform CoAP to HTTP?

I searched but did not found any example showing on how to convert CoAP request or response to HTTP request.
Basically what I want to do is CoAP request POST some data from device to a server which will translate it and do HTTP request POST to other server to be save inside the database.
While the part to save the data is not a major problem right now, I did not managed to find any example script showing how to convert from CoAP to HTTP.
I already looked at coapthon , aiocoap but since aiocoap requires python 3.5,(I use python 2.7) that left me with coapthon. Unfortunately coapthon only has HTTP to CoAP proxy while CoAP to HTTP is still in development.
If anyone know other project regarding this or has any opinion on how to solve this, I am glad if you can share it. Thank you.
That is called Protocol Interoperability. You Need a CoAP - HTTP and HTTP - CoAP proxy that can translate the messages between them.
Here is californium-proxy on GitHub, I am using it already. Here is the example that shows how to use it.

Access Siebel WSDL through Python Packages (SOAPpy, suds, requests)

I am trying to access Siebel WSDL through python module.
My End Scenario is creating Service request in Siebel through external link.
I have tried,
Requests, Suds and soapPY.
When Importing WSDL file to SOAP-UI after making changes to URL and appending user-name and password to same and making changes in body, Its working for me and giving 200 server response.
When trying to access the same with postman(rest client) and giving URL with user name and password added. And passing the required XML as part of body I am getting 500 internal server error.
Not understanding where difference is coming in the way the request is going through soapUI and postman.
What difference in I have to make, to make it work with postman.
What is the right way to consume a WSDL service in python.
SOAP Input:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aud="http://siebel.com/Service/ServiceReqs" xmlns:aud1="http://www.siebel.com/xml/%20Service%20Request%20IO">
<soapenv:Header/>
<soapenv:Body>
<aud:SRQueryByExample_Input>
<aud1:ListOfServiceRequestIo>
<aud1:ServiceRequestOpen Operation="?">
<aud1:IntegrationId>0000123</aud1:IntegrationId>
</aud1:ServiceRequestOpen>
</aud1:ListOfAudetemiServiceRequestIo>
</aud:SRQueryByExample_Input>
</soapenv:Body>
</soapenv:Envelope>
I need to know here if Integration ID is something that I need to pass dynamically how to achieve same.
Many thank for your time
If you are getting a 500 error, that means the request is stuck at the web server, and has not yet hit the siebel server behind it. If the error is due to something missing in the xml, you will get a "SBL-" error code in the response. Until you get that, and are getting 500 errors, the request SOAP has not yet hit the siebel server.
I don't know python, but my suggestion would be to capture the RAW message going from your python script and compare that to the RAW message in SOAP-UI. Specially check the SOAPAction string, it should have a forward slash (/) and a colon (:). "Content-Type", "text/xml"
For further debugging, you will have to check the webserver logs to see how the message arrives there.

Python-Eve: formatting GET response to HTTP 200

I have Python-Eve running with MongoDB on a Ubuntu VM. I am trying to write an api to handle POST requests from an Iridium RockBLOCK modem. I have tested the API with Chrome Postman, and am able to successfully POST data.
When I try and send messages from my RockBLOCK I get 422 error messages on the VM. I am pretty sure this is because the RockBLOCK is not able to handle XML or JSON data, and is set up to simply look for an HTTP 200 response.
So how would I setup eve to respond with solely HTTP 200 when the POST request is received?
API Format taken from RockBLOCK Web Services Guide.
The 422 is returned from Eve when a validation error occurs. I would look into your request payload and make sure it adheres to validation rules. A typical example of a response like this would be when you have a unique rule for a field, and a POST comes in with an already used value for that field.
So how would I setup eve to respond with solely HTTP 200 when the POST request is received?
Right now you can disable either JSON or XML responses by respectively setting JSON = False or XML = False, but not both. Since Eve is a Flask application you could look into changing the response on the flight but again, given the error you are getting I don't think that is the problem you are facing right now.

Categories

Resources