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
user1330225
  • 177
  • 1
  • 2
  • 8

2 Answers2

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.

Community
  • 1
  • 1
user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • 2
    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 Sep 28 '15 at 14:28
  • 1
    @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 Sep 28 '15 at 15:31
  • @user4815162342 Please update your answer. The links are not available now. – Rahul K P Jun 20 '16 at 10:50
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

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
Mp0int
  • 18,172
  • 15
  • 83
  • 114