2010-12-09 73 views
3

任何人都可以得到suds soap庫來使用NetSuite WSDL嗎?我嘗試創建客戶端時遇到此錯誤。任何人都可以獲得suds soap庫以使用NetSuite WSDL?

from suds.client import Client 

#url = 'http://mssoapinterop.org/asmx/simple.asmx?WSDL' 
url = 'https://webservices.netsuite.com/wsdl/v2009_2_0/netsuite.wsdl' 
client = Client(url) 
print client 


Traceback (most recent call last): 
client = Client(url) 
File "build\bdist.win32\egg\suds\client.py", line 112, in __init__ 
File "build\bdist.win32\egg\suds\reader.py", line 152, in open 
File "build\bdist.win32\egg\suds\wsdl.py", line 158, in __init__ 
File "build\bdist.win32\egg\suds\wsdl.py", line 207, in resolve 
File "build\bdist.win32\egg\suds\wsdl.py", line 662, in resolve 
File "build\bdist.win32\egg\suds\wsdl.py", line 757, in resolvefaults 
Exception: fault 'ExceededRecordCountFault' not defined in portType 'NetSuitePortType' 
+0

它看起來像它不處理WSDL中的進口。你有沒有確認泡沫與外部進口? – Craig 2010-12-09 22:22:47

回答

0

https://webservices.netsuite.com/wsdl/v2010_2_0/netsuite.wsdl

我發現它是失敗的這部分之間的驗證:

<operation name="checkAsyncStatus"> 
    <input name="checkAsyncStatusRequest" message="tns:checkAsyncStatusRequest"/> 
    <output name="checkAsyncStatusResponse" message="tns:checkAsyncStatusResponse"/> 
    <fault name="InvalidSessionFault" message="tns:InvalidSessionFault"/> 
    <fault name="InvalidCredentialsFault" message="tns:InvalidCredentialsFault"/> 
    <fault name="ExceededRequestLimitFault" message="tns:ExceededRequestLimitFault"/> -- mismatch 
    <fault name="UnexpectedErrorFault" message="tns:UnexpectedErrorFault"/> 
    <fault name="AsyncFault" message="tns:AsyncFault"/> 
</operation> 

這部分:

<operation name="checkAsyncStatus"> 
    <soap:operation soapAction="checkAsyncStatus"/> 
    <input name="checkAsyncStatusRequest"> 
     <soap:header message="tns:headers" part="passport" use="literal"/> 
     <soap:header message="tns:headers" part="applicationInfo" use="literal"/> 
     <soap:header message="tns:headers" part="partnerInfo" use="literal"/> 
     <soap:header message="tns:headers" part="preferences" use="literal"/> 
     <soap:body use="literal"/> 
    </input> 
    <output name="checkAsyncStatusResponse"> 
     <soap:header message="tns:headers" part="documentInfo" use="literal"/> 
     <soap:body use="literal"/> 
    </output> 
    <fault name="InvalidSessionFault"> 
     <soap:fault name="InvalidSessionFault" use="literal"/> 
    </fault> 
    <fault name="InvalidCredentialsFault"> 
     <soap:fault name="InvalidCredentialsFault" use="literal"/> 
    </fault> 
    <fault name="ExceededRequestLimitFault"> 
     <soap:fault name="ExceededRecordCountFault" use="literal"/> -- mismatch 
    </fault> 
    <fault name="UnexpectedErrorFault"> 
     <soap:fault name="UnexpectedErrorFault" use="literal"/> 
    </fault> 
    <fault name="AsyncFault"> 
     <soap:fault name="AsyncFault" use="literal"/> 
    </fault> 
</operation> 

我改變了這一點:

<fault name="ExceededRequestLimitFault"> 
    <soap:fault name="ExceededRecordCountFault" use="literal"/> 
</fault> 

這樣:

<fault name="ExceededRequestLimitFault"> 
    <soap:fault name="ExceededRequestLimitFault" use="literal"/> 
</fault> 

修改它允許Suds創建客戶端。就像約翰提到的那樣,解析需要很長時間(超過兩分鐘)。我還沒有嘗試使用checkAsyncStatus來查看它是否工作。

3

是的,泡沫可以連接到NetSuite,但處理WSDL需要很長時間。

下面是一些示例代碼:

# Open NetSuite Session 
wsdlNetSuite = 'https://webservices.netsuite.com/wsdl/v2010_1_0/netsuite.wsdl' 
client = Client(wsdlNetSuite) 

# Login 
passport = client.factory.create('ns4:Passport') 
passport.email = '[email protected]' 
passport.password = 'ABC123' 
passport.account = 123 
loginResponse = client.service.login(passport) 
print 'Login Response: ' 
print loginResponse.status 

# Get a record 
recordRef = client.factory.create('ns4:RecordRef') 
recordRef._internalId = 127842 
recordRef._type = 'invoice' 
record = client.service.get(recordRef) 
print record 

您可能還需要嘗試Python和SUDS版本的各種組合。這不是一個特別可靠的圖書館。

+0

我仍然遇到與您的語法示例相同的錯誤。我正在使用Python 2.7和Suds 0.4。你使用不同的版本? – tponthieux 2011-01-12 17:24:38

+1

上面的例子使用Python 2.4.3和SUDS 0.3.6。 Client()調用返回需要2分鐘。 – 2011-02-19 22:44:52

1

雖然不是最好的辦法,但如果你絕望,你可以繼續嘗試不同版本的wsdl。我得到了同樣的錯誤信息,所以我一直試圖直到有人工作。

'https://webservices.netsuite.com/wsdl/v2010_2_0/netsuite.wsdl' 
'https://webservices.netsuite.com/wsdl/v2010_1_0/netsuite.wsdl' 
'https://webservices.netsuite.com/wsdl/v2009_2_0/netsuite.wsdl' 
'https://webservices.netsuite.com/wsdl/v2009_1_0/netsuite.wsdl' 

'https://webservices.netsuite.com/wsdl/v2009_1_0/netsuite.wsdl' 終於爲我工作

編輯:基於tponthieux的回答 ,我意識到我在這個順序去現在你可以使用肥皂水插件功能修復的WSDL(我只想對他的回答發表評論,但我沒有信譽尚未:():

import re 

from suds.client import Client 
from suds.plugin import DocumentPlugin 

NetSuite_wsdl = 'https://webservices.netsuite.com/wsdl/v2010_2_0/netsuite.wsdl' 


class Fix_NS_wsdl(DocumentPlugin): 
    bad_fault = re.compile(r"(ExceededRequestLimitFault)" 
      r"(\">\s*<soap:fault name=\")(ExceededRecordCountFault)") 

    def loaded(self, context): 
     if context.url == NetSuite_wsdl: 
      context.document = self.bad_fault.sub(r"\1\2\1", context.document) 

client = Client(NetSuite_wsdl, plugins=[Fix_NS_wsdl()]) 
0

如果你想要做一個保存WSDL一次性修復,而不是做每次(這需要一段時間)的修復這裏的是我用

:%s/RequestLimitFault">\n\t*<soap\:fault name=\"ExceededRecordCountFault/RequestLimitFault\"\>\r\t\t\t\t<soap\:fault name=\"Exce ededRequestLimitFault/gc 

一個VIM替換命令這部作品在2010 Netsuite WSDL也不得不這樣做的2012 Netsuite WSDL(你認爲他們會在兩年後有固定的)

2

這是一個有點晚了,但備案附上如何可以與 NetSuite的SuiteTalk工作方式使用Python Zeep的SOAP API。

使用Python和Zeep跟蹤添加客戶的NetSuite SOAP登錄示例。

# pip3 install zeep 
from zeep import Client 

WSDL_URL = 'https://webservices.sandbox.netsuite.com/wsdl/v2016_1_0/netsuite.wsdl' 
NS_EMAIL = '[email protected]' 
NS_PASSWORD = '*********' 
NS_ROLE = '1111' 
NS_ACCOUNT = '1111111' 
NS_APPID = 'FFFFFFFF-FFFF-0000-0000-FFFFFFFFFFFF' 


def login_client(): 
    client = Client(WSDL_URL) 
    Passport = client.get_type('ns1:Passport') 
    AppInfo = client.get_type('ns5:ApplicationInfo') 
    passport = Passport(email=NS_EMAIL, password=NS_PASSWORD, account=NS_ACCOUNT) 
    app_info = AppInfo(applicationId=NS_APPID) 
    login = client.service.login(passport=passport, 
           _soapheaders={'applicationInfo': app_info}) 
    print('Login Response: ', login.status) 
    return client 


# Example usage 
client = login_client() 

# add a customer 
Customer = client.get_type('ns14:Customer') 
customer = Customer(
    lastName='Joe', 
    firstName='Bloggs', 
    email='[email protected]' 
) 
response = client.service.add(customer) 
print(response) 

參見:https://github.com/fmalina/python-netsuite

相關問題