python - 如何使用 Python 调用 Soap API

标签 python api soap

虽然我过去使用过 API,但这是我尝试使用的第一个 SOAP。我从 SOAP 教程中复制、粘贴和更改了一些代码,但我已经看到它在 10 个不同的示例中以 10 种不同的方式完成,但没有一个在解释代码时非常清楚。也许以下代码不是最好的方法,但这就是我寻求帮助和明确方向的原因。非常感谢。

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

最佳答案

不要尝试推出自己的 SOAP 客户端 — 尽管名称如此,但 SOAP 绝非简单。

查找任何decent SOAP library并将其用于您的 SOAP 通信。

一般来说,which SOAP library is "the best"的问题本质上是有争议的,随着项目的流行和过时,答案往往会随着时间而变化。选择最适合用例的一种,任何一种都可能比您自己编写更好。

关于python - 如何使用 Python 调用 Soap API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15436749/

相关文章:

python - 在 python 中高效地找到数组的范围?

python - Python:从单独的线中的点绘制一条垂直线

python - 亚马逊 AWS EC2 : How to host an API and a website on EC2 instance

java - 在Netbean中使用unirest发送短信

c - Windows 有可以从 C 调用的 JSON API 吗?

python - 在 Python 中设置 getaddrinfo() 超时

python - 了解 maplotlib 以及如何使用单个数字格式化 matplotlib 轴?

java - 当函数没有返回值时,Delphi XE2 是否正确从 Java/Axis2 导入 WSDL?

java - 没有复杂类型的 Apache CXF Soap wsdl

java - 在 Axis2/Rampart 中,如何忽略接收方/响应方的 SignatureToken?