Skip to content Skip to sidebar Skip to footer

Has Anyone Been Able To Get The Suds Soap Library To Work With The Netsuite Wsdl?

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://mss

Solution 1:

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

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

Solution 2:

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 = '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)

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

Solution 3:

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'classFix_NS_wsdl(DocumentPlugin):
    bad_fault = re.compile(r"(ExceededRequestLimitFault)"r"(\">\s*<soap:fault name=\")(ExceededRecordCountFault)")

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

Solution 4:

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)

Solution 5:

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

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

<operationname="checkAsyncStatus"><inputname="checkAsyncStatusRequest"message="tns:checkAsyncStatusRequest"/><outputname="checkAsyncStatusResponse"message="tns:checkAsyncStatusResponse"/><faultname="InvalidSessionFault"message="tns:InvalidSessionFault"/><faultname="InvalidCredentialsFault"message="tns:InvalidCredentialsFault"/><faultname="ExceededRequestLimitFault"message="tns:ExceededRequestLimitFault"/> -- mismatch
    <faultname="UnexpectedErrorFault"message="tns:UnexpectedErrorFault"/><faultname="AsyncFault"message="tns:AsyncFault"/></operation>

and this part:

<operationname="checkAsyncStatus"><soap:operationsoapAction="checkAsyncStatus"/><inputname="checkAsyncStatusRequest"><soap:headermessage="tns:headers"part="passport"use="literal"/><soap:headermessage="tns:headers"part="applicationInfo"use="literal"/><soap:headermessage="tns:headers"part="partnerInfo"use="literal"/><soap:headermessage="tns:headers"part="preferences"use="literal"/><soap:bodyuse="literal"/></input><outputname="checkAsyncStatusResponse"><soap:headermessage="tns:headers"part="documentInfo"use="literal"/><soap:bodyuse="literal"/></output><faultname="InvalidSessionFault"><soap:faultname="InvalidSessionFault"use="literal"/></fault><faultname="InvalidCredentialsFault"><soap:faultname="InvalidCredentialsFault"use="literal"/></fault><faultname="ExceededRequestLimitFault"><soap:faultname="ExceededRecordCountFault"use="literal"/> -- mismatch
    </fault><faultname="UnexpectedErrorFault"><soap:faultname="UnexpectedErrorFault"use="literal"/></fault><faultname="AsyncFault"><soap:faultname="AsyncFault"use="literal"/></fault></operation>

I changed this:

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

to this:

<faultname="ExceededRequestLimitFault"><soap:faultname="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.

Post a Comment for "Has Anyone Been Able To Get The Suds Soap Library To Work With The Netsuite Wsdl?"