来自Python的SOAP请求

时间:2019-12-17 08:32:51

标签: python api soap

伙计们! 我有一个小问题,我正在尝试编写python脚本以从一项测试服务获取目录。我正在发送带有描述wsdl服务的长xml正文的请求并接收响应,但这不是我想要看到的结果)有人,请告诉我我做的不好)

以下是如何使用此服务获取目录的示例: link1 link2 这是来自示例的响应: link3

这是我的脚本,我对

import requests

wsdl_url="https://apitest.merlion.com/re/mlservice3?wsdl"
#headers = {'content-type': 'application/soap+xml'}
params = {'login': 'TC0053432|API', 
	'password': 'XPE33UcS32',
	'encoding': 'UTF-8'
}

body = """
<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://apitest.merlion.com/re/mlservice3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
	<ns1:getCatalog>
		<cat_id xsi:type="xsd:string">All</cat_id>
	</ns1:getCatalog>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
"""

response = requests.post(wsdl_url, data=body, headers=params)

print(response)
print(response.content)

1 个答案:

答案 0 :(得分:0)

您应该首先获得SOAP客户端库,而不是请求。

https://wiki.python.org/moin/WebServices#SOAP