So I’m trying to access this api https://www.clarityaccounting.com/api-docs/ using SUDS. Here is the code that should work:
from suds.client import Client
client = Client('https://www.clarityaccounting.com/api/v1?wsdl')
token = client.service.doLogin('demo', 'demo', 'www.kashoo.com', 'en_US', 300000)
But I get this error:
WebFault: Server raised fault: 'No such operation: (HTTP GET PATH_INFO: /api/v1)'
Their support guy says that the request should look like this:
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:api="http://api.service.books/">
<SOAP-ENV:Body>
<api:doLogin>
<username>demo</username>
<password>demo</password>
<siteName>www.kashoo.com</siteName>
<locale>en_US</locale>
<duration>300000</duration>
</api:doLogin>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But SUDS’ looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:ns0="http://api.service.books/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:doLogin>
<username>demo</username>
<password>demo</password>
<siteName>www.kashoo.com</siteName>
<locale>en_US</locale>
<duration>300000</duration>
</ns0:doLogin>
</ns1:Body>
</SOAP-ENV:Envelope>
I’m a real SOAP and SUDS newbie but I heard that SUDS is the best SOAP library to use from here: What SOAP client libraries exist for Python, and where is the documentation for them?
So my question is simply what are the crucial parts that are different and that are making the request fail and how can I configure SUDS to send the properly formatted request?
At first glance looks like the problem you’re having is with SSL. You are accessing an https URL, and the Transport handler for suds.client talks http by default.
The problem
If you look at the bottom of the WSDL it is specifying the default location as
http://www.clarityaccounting.com/api/v1, which is an http URL, but the WSDL is SSL.If you do an http GET on that URL, you get the error message you received:
The Solution
To fix this you need to override the default location when you call the
Clientconstructor to make it stick with https:Victory!
Pro tip for future debugging purposes: Turn on full logging debugging. SUDS uses the standard
logginglibrary, so it gives you a lot of control. So I cranked it all up toDEBUG:This is what helped me narrow it down, because it was clearly saying it was sending over http:
And then the response said so as well: