Reputation: 26655
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?
Upvotes: 1
Views: 3925
Reputation: 171
#Works only in 2.7 Python. Does not work in Python 3.0 version
from suds.client import Client
from suds.sax.text import Raw
client = Client('https://www.e-conomic.com/secure/api1/EconomicWebService.asmx?WSDL')
xml = Raw('--Paste your entire xml --')
Response_XML= (client.service.MethodName(__inject={'msg':xml}))
-- You will get all your xml response in Response_XML variable
Upvotes: 1
Reputation: 21243
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.
Upvotes: 3