有谁能够让肥皂库与 NetSuite WSDL 一起使用吗?

发布于 2024-10-07 11:07:04 字数 809 浏览 4 评论 0原文

有谁能够让肥皂库与 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'

Has anyone been able to get the suds soap library to work with the NetSuite WSDL? I get this error when I try to create a client.

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

幽蝶幻影 2024-10-14 11:07:04

是的,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 = '[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 版本的各种组合。它不是一个特别可靠的库。

Yes, suds can connect to NetSuite, but it takes a long time to process the WSDL.

Here's some sample code:

# 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

You might also need to try various combinations of Python and SUDS versions. It's not a particularly reliable library.

糖果控 2024-10-14 11:07:04

虽然有点晚了,但为了记录,我附上了一种如何使用的方法
使用 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 = '[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

It is a bit late, but for the record I attach a way of how one can work with
NetSuite SuiteTalk SOAP API using Python Zeep.

Example of NetSuite SOAP login with Python and Zeep followed by adding a customer.

# 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)

See also: https://github.com/fmalina/python-netsuite

苄①跕圉湢 2024-10-14 11:07:04

虽然这不是最好的方法,但如果您绝望的话,您可以继续尝试他们的 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()])

Though not the best way to do things, if you're desperate, you can keep trying different versions of their wsdl. I was getting the same error message, so I kept trying until one worked. I went in this order:

'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' finally worked for me

EDIT:
Based on tponthieux's answer, I realize now that you can use the suds plugin feature to fix the wsdl (I would simply comment on his answer, but I don't have the reputation yet :( ):

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()])

如果您想对已保存的 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(您认为他们会在两年后修复它)

If you want to do a one-off fix on a saved WSDL instead of doing the fix every time (which takes a while) here is a VIM substitution command that I used

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

This works on the 2010 Netsuite WSDL and also had to do it for the 2012 Netsuite WSDL (you think they would have fixed it after two years)

怪我太投入 2024-10-14 11:07:04

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 来查看它是否有效。

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

I found that it was failing on a validation between this part:

<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>

and this part:

<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>

I changed this:

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

to this:

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

The modification allows Suds to create the client. Like John mentioned, it does take forever to parse(more than two minutes). I haven't tried using checkAsyncStatus to see if it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文