12

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
0

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

3 Comments

a la Python documentation rules, there's no reason to tell a user what not to do. Rather, you should explain the problems in the OP code or simply suggest that this may be a solution, without discouraging another one.
@Yuval The answer does suggest a better solution - see the second paragraph. Advice against a not-invented-here approach was given with good reason, in good faith, and in answer to a question clearly asking for directions. Two years later, it's still good advice, even if you disagree with the tone.
@user4815162342 Please update your answer. The links are not available now.
1

I can advise you to use suds. It is quite good and widely used.

Update: Base suds project is not active for a long time. There is a new fork of the current project which is quite acive now.

asuds project

1 Comment

the url is no longer working, can you provide a new url ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.