[英]What's wrong with my Python SOAPpy webservice call?
我正在尝试使用 Python 解释器中的以下代码来调用简单的 SOAP 网络服务:
from SOAPpy import WSDL
wsdl = "http://www.webservicex.net/whois.asmx?wsdl"
proxy = WSDL.Proxy(wsdl)
proxy.soapproxy.config.dumpSOAPOut=1
proxy.soapproxy.config.dumpSOAPIn=1
proxy.GetWhoIS(HostName="google.com")
(是的,我是 Python 的新手,正在做 Diveintopython 的事情......)
对 GetWhoIS 方法的调用失败 - 否则我不会在这里问,我猜。 这是我即将传出的 SOAP:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<GetWhoIS SOAP-ENC:root="1">
<HostName xsi:type="xsd:string">google.com</HostName>
</GetWhoIS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是传入的响应。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>
System.Web.Services.Protocols.SoapException:
Server was unable to process request. --->
System.ArgumentNullException: Value cannot be null.
at whois.whois.GetWhoIS(String HostName)
--- End of inner exception stack trace ---
</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
(手动格式化以便于阅读)
谁能告诉我我做错了什么?
理想情况下,无论是就 SOAPpy 的使用而言,还是 SOAP 消息不正确的原因。
谢谢!
你的电话对我来说似乎没问题,我认为这可能是一个肥皂问题或错误配置的服务器(尽管我没有彻底检查过)。
该文档还暗示了 soappy 和 webservicex.net 之间的不兼容性: http://users.jyu.fi/~mweber/teaching/ITKS545/exercises/ex5.pdf
在这种特定情况下,我将如何解决这个问题?
import urllib
url_handle = urllib.urlopen( "http://www.webservicex.net/whois.asmx/GetWhoIS?HostName=%s" \
% ("www.google.com") )
print url_handle.read()
正如@ChristopheD 所提到的,SOAPpy 似乎对于 WDSL 的某些配置有问题。
我尝试使用 suds(Ubuntu 上的 sudo easy_install suds),第一次工作。
from suds.client import Client
client = Client('http://www.webservicex.net/whois.asmx?wsdl')
client.service.run_GetWhoIS(HostName="google.com")
乔布斯是个好人。
由于某种原因,客户端使用几乎不再使用的过时形式发送请求(“SOAP 第 5 节编码”)。 你可以根据这个来判断:
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
但是基于 WSDL,该服务只接受常规的 SOAP 消息。 因此,WSDL 解析您正在使用的 SOAP 库的一部分很可能有问题。
请在此处查看我对另一个问题的回答。 .net 需要在 soap 操作前附加名称空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.