Skip to main content
 首页 » 编程设计

python之我的 Python SOAPpy 网络服务调用有什么问题

2025年05月04日26wuhuacong

我正在尝试使用 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. ---&gt; 
           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()