While I've used APIs in the past, this is the first SOAP I've attempted to use. I copy, pasted, and changed around some of this code from a SOAP tutorial, but I've seen it done 10 different ways in 10 different examples, yet none are very clear in explaining the code. Maybe the following code isn't the best way to do it, but that's why I'm looking for some help and a clear direction to go in. Thanks so much.
import string, os, sys, httplib
server_addr = "auctions.godaddy.com"
service_action = "GdAuctionsBiddingWSAPI/GetAuctionList"
body = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.example.com/services/wsdl/2.0">
<soapenv:Header/>
<soapenv:Body>
<ns:serviceListRequest>
<ns:userInfo>
</ns:userInfo>
</ns:serviceListRequest>
</soapenv:Body>
</soapenv:Envelope>"""
request = httplib.HTTPConnection(server_addr)
request.putrequest("POST", service_action)
request.putheader("Accept", "application/soap+xml, application/dime, multipart/related, text/*")
request.putheader("Content-Type", "text/xml; charset=utf-8")
request.putheader("Cache-Control", "no-cache")
request.putheader("Pragma", "no-cache")
request.putheader("SOAPAction", "https://auctions.godaddy.com/gdAuctionsWSAPI/gdAuctionsBiddingWS.asmx?op=GetAuctionList" + server_addr + service_action)
request.putheader("Content-Length", "length")
request.putheader("apiKey", "xxxxxx")
request.putheader("pageNumber", "1")
request.putheader("rowsPerPage", "1")
request.putheader("beginsWithKeyword", "word")
request.endheaders()
request.send(body)
response = request.getresponse().read()
print response
Now let’s look at an example, to call XML SOAP Web Service in Python. To call SOAP API you need to know Request XML Body Structure. If you are not sure how to create SOAP Request body then no worries. Check this article to learn how to generate SOAP Request body using the Free tool SoapUI.
If you're going to interact witha SOAP API you need a SOAP client to parse the WSDL url or else you won't be able to create a client to call like an RPC. Zeep is one that's available for Python. You can't just interact with it with CURL or something like that. How you're trying to interact with the API is not really the way SOAP works.
Once your SOAP Request XML is ready, Click the Play button in the toolbar to execute SOAP API Request and Response will appear in Right side panel. Test SOAP API using SoapUI Tool (Change Default XML Body / Parameters, Execute and See Response)
The Content-Type: application/soap+xml request header informs the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a Content-Type: application/soap+xml response header. The Python code was automatically generated for the Make SOAP Request example.
Don't try to roll your own SOAP client — despite the name, SOAP is anything but simple.
Find any decent SOAP library and use it for your SOAP communication.
Generally, the question of which SOAP library is "the best" is by nature contentious and the answer tends to vary with time, as projects come into and go out of fashion. Pick the one that works well for your use case, and any one is likely to be better than writing your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With