有没有人能够使用肥皂肥皂库来使用NetSuite WSDL?

时间:2010-12-09 15:55:44

标签: python soap netsuite

有没有人能够使用suds肥皂库来使用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'

5 个答案:

答案 0 :(得分:3)

是的,suds可以连接到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 = 'username@web.com'
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版本的各种组合。它不是一个特别可靠的图书馆。

答案 1 :(得分:3)

有点晚了,但是为了记录,我附上了一个如何使用的方式 使用Python Zeep的NetSuite SuiteTalk 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 = 'admin@example.com'
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='joe@example.com'
)
response = client.service.add(customer)
print(response)

另请参阅:https://github.com/fmalina/python-netsuite

答案 2 :(得分: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的回答,我现在意识到你可以使用suds插件功能来修复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()])

答案 3 :(得分: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创建客户端。就像John提到的那样,它需要永远解析(超过两分钟)。我没有尝试使用checkAsyncStatus来查看它是否有效。

答案 4 :(得分:0)

如果你想对已保存的WSDL进行一次性修复而不是每次都进行修复(这需要一段时间),这里是我使用的VIM替换命令

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

这适用于2010 Netsuite WSDL,还必须为2012 Netsuite WSDL执行此操作(您认为他们会在两年后修复它)