2009-08-25 62 views
10

我有一個使用Suds調用SOAP的Web服務(該服務是寫在ASP.net)以下簡單的Python測試腳本:的Python /肥皂水:類型未找到:「XS:複雜類型」

from suds.client import Client 

url = 'http://someURL.asmx?WSDL' 

client = Client(url) 

result = client.service.GetPackageDetails("MyPackage" ) 

print result 

當我運行這個測試腳本,我收到以下錯誤(使用代碼標籤,因爲它不換行):

No handlers could be found for logger "suds.bindings.unmarshaller" 
Traceback (most recent call last): 
    File "sudsTest.py", line 9, in <module> 
    result = client.service.GetPackageDetails("t3db" ) 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 240, in __call__ 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 379, in call 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 240, in __call__ 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 422, in call 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 480, in invoke 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 505, in send 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/client.py", line 537, in succeeded 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/binding.py", line 149, in get_reply 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 303, in process 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 88, in process 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 104, in append 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 181, in append_children 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 104, in append 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 181, in append_children 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 104, in append 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 181, in append_children 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 102, in append 
    File "build/bdist.cygwin-1.5.25-i686/egg/suds/bindings/unmarshaller.py", line 324, in start 
suds.TypeNotFound: Type not found: 'xs:complexType' 

在源WSDL文件的頭展望(重新格式化,以適合):

<?xml version="1.0" encoding="utf-8" ?> 
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:s="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:tns="http://http://someInternalURL/webservices.asmx" 
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
targetNamespace="http://someURL.asmx" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 

我根據輸出的最後一行猜測:

suds.TypeNotFound: Type not found: 'xs:complexType' 

,我需要用Sud酒店的doctor class固定的模式,但作爲一個SOAP新手,我不知道需要什麼固定在我的情況。有沒有人有任何使用Suds修復/更正架構的經驗?

+1

我只是嘗試了一個簡單的C#測試應用程序,它可以連接到這個服務很好(但後來服務是基於ASP.net)。它可能是微軟特定的默認不支持Suds? – Danielb 2009-08-25 22:06:08

+0

它看起來像服務試圖返回一個DataSet。我在記錄器中看到以下內容: 警告:suds.bindings.unmarshaller:屬性(IsDataSet)類型,未找到 警告:suds.bindings.unmarshaller:屬性(名稱)類型,未找到 錯誤:泡沫.bindings.unmarshaller:架構:0x7fce048c – Danielb 2009-08-27 22:57:21

+0

對我來說聽起來像SUDS不是從指定數據集結構的標記導入的。你是否搜索過你的WSDL進口產品? 如果這是答案,那麼SUDS的ImportDoctor應該能夠提供幫助。示例在https://fedorahosted.org/suds/wiki/Documentation#FIXINGBROKENSCHEMAs – ewall 2009-08-31 17:42:39

回答

15

Ewall的資源是一個不錯的選擇。如果您嘗試在泡沫塑料卡票據中搜索,則可以看到其他人遇到問題similar to yours,但具有不同的對象類型。學習它的例子以及它們如何導入它們的命名空間是一種很好的方法。

The problem is that your wsdl contains a schema definition that references the (...) but fails to import the " http://schemas.xmlsoap.org/soap/encoding/ " namespace (and associated schema) properly. The schema can be patched at runtime using the schema ImportDoctor as discussed here: https://fedorahosted.org/suds/wiki/Documentation#FIXINGBROKENSCHEMAs .

This is a fairly common problem.

A commonly referenced schema (that is not imported) is the SOAP section 5 encoding schema. This can now be fixed as follows:

(所有重點都是我的)。

您可以嘗試這些文檔提供的行,添加WSDL中提供的名稱空間。這可能是一個嘗試錯誤的事情。

imp = Import('http://schemas.xmlsoap.org/soap/encoding/') 
# Below is your targetNamespace presented in WSDL. Remember 
# that you can add more namespaces by appending more imp.filter.add 
imp.filter.add('http://someURL.asmx') 
doctor = ImportDoctor(imp) 
client = Client(url, doctor=doctor) 

你沒有提供你正在使用的WSDL,我想你有理由不顯示給我們......所以我覺得你必須自己去嘗試這些可能性。祝你好運!

+0

我似乎無法接受這個答案,因爲某種原因:( – Danielb 2009-11-05 17:09:11

+0

我知道它並不能完全解決你的問題......但是你不能提供你的wsdl,我不能在這種情況下試圖找出確切的問題,所以我試圖幫助你一些通用的「盲目調試建議」,看看你是否可以自己提出問題。既然你寫了這個評論,我想你沒有找到解決你的問題的方法......你是否嘗試過Suds的官方支持? – GmonC 2009-11-05 18:49:10