簡體   English   中英

我的 Python SOAPpy Web 服務調用有什么問題?

[英]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. ---&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()

正如@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM