0

I am using suds to send XML and I got my request working, but I'm really confused by how to replicate my results using XML. I have the XML request that my suds client is sending by using:

from suds.client import Client
ulr = "xxxxxxx"
client = Client(url)

...

client.last_received.str()

but I'm not sure where I would send that request to if I was using the requests library. How would I replicate the request from the suds client in a python request?

Rob
  • 3,333
  • 5
  • 28
  • 71
  • Why not just use the SOAP client? SOAP defines a client/server RPC and can be quite complex. `suds` turns it into a simpler python API. Seems like you are going in the wrong direction fiddling with the underlying xml. – tdelaney Dec 31 '15 at 21:14

1 Answers1

1

Most SOAP APIs are just over plain HTTP, use POST - and therefore are easily mimicked with any standard HTTP client such as Requests.

First look here to see how to view the headers and body that suds is sending - it is then a matter of replicating these headers/XML body and passing them into the Requests library.

One defining characteristic in 99% of all HTTP SOAP API's is that your request is going to the same end-point for each request (for example 'http://yyy.com:8080/Posting/LoadPosting.svc), and the actual action is specified in the header using SOAPAction header). Contrast this to a RESTful API where the action is implied with the verb + end-point you call (POST /user, GET /menu etc.)

Community
  • 1
  • 1
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
  • ya but what exactly is the url it's sending the suds request to? like if my suds client is like: from suds.client import Client import datetime #gets all service descriptions in a single file url = 'http://xxxxxxxxx.com:8080//Posting/LoadPosting.svc?singleWsdl' – Rob Dec 31 '15 at 21:10
  • client = Client(url), , result = client.service.PostLoads(request),,,, is it still sending stuff to the original url? I'm just very unfamiliar with SOAP but want to take the client out of my app – Rob Dec 31 '15 at 21:11
  • You most likely won't want to be implementing your own WSDL parser - that's probably the hardest part of writing a HTTP SOAP client. I'm assuming you just want to mimic the calls using Requests, but not a full drop-in replacement including WSDL parsing – Martin Konecny Dec 31 '15 at 21:12
  • ya exactly, is there an easy way to do this? – Rob Dec 31 '15 at 21:12
  • to elaborate, i have a very specific request that i want to consistently recreate by subbing in paramaters. Can I just create an XML template, substitute the parameters and submit? – Rob Dec 31 '15 at 21:16
  • You simply need to look into which end-point your suds client is hitting (it should be the same each-time), and then you need to grap the `SOAPAction` header. – Martin Konecny Dec 31 '15 at 21:16
  • "Can I just create an XML template, substitute the parameters and submit?" - yes exactly. I'm trying to say that putting Suds into debug/verbose mode is the easiest way so you can simply copy all the data except the parts you want to change (like the body). Seems like the headers will be the same since you have only one specific request. – Martin Konecny Dec 31 '15 at 21:18
  • hmm, so i'm trying to get the request to work unsuccessfully, is there a simple way to convert my suds request to a requests? I am using a suds service defined like ns1:LoadPostingRequest, how does that impact the url? – Rob Dec 31 '15 at 21:52