Dac Saunders Dac Saunders - 9 days ago 5
Python Question

How to connect to webservice using suds?

I want to connect to a webservice called e-conomic to sync data from my webshop with the e-conomic bookkeeping system. But I'm stuck at the beginning how to start a connection.

I've got an e-conomic account, a username and a password and I installed the suds library to make the call:

>>> from suds.client import Client
>>> c = Client('https://www.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL')
>>>


Then what?

The documentation is here and what I want to do is create a new order like described here.

My code that is part of my app is only just started and I don't know how to specify my account in the SOAP request:

from suds.client import Client

class Economic(NewBaseHandler):

def get(self):
url = 'https://www.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL'
client = Client(url)
self.response.out.write('client: %s' % str(client))


Can you tell me how to proceed?

Answer

You have to call the webservice with the service method of the Client.

>>> from suds.client import Client
>>> c = Client('https://www.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL')
>>> c.service.Account_Create(10, '20', 'ProfitAndLoss')
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 240, in __call__
    return target.call(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 379, in call
    return method(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 240, in __call__
    return target.call(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 422, in call
    return client.invoke(args, kwargs)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 480, in invoke
    result = self.send(msg)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 511, in send
    result = self.failed(binding, e)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/client.py", line 562, in failed
    r, p = binding.get_fault(reply)
  File "/usr/lib/python2.7/site-packages/suds-0.3.6-py2.7.egg/suds/bindings/binding.py", line 226, in get_fault
    raise WebFault(p, faultroot)
WebFault: Server raised fault: 'Economic.Api.Exceptions.AuthenticationException(E02250): User is not authenticated. Access denied. {id=131496672}'

I got this error because user is not authenticated. There might be some service or some key by which they will authenticate the user. You need that key then you can call the services.