CMDBuild Forum

How to connect the webservice cmdbuild based on python coding?

When I try to authenticate my cmdbuild webservice(with the account)using suds  modules of python, I got a "suds.WebFault" error requests. I checked the account password is corrected.

Now,the problem is that it  responses 'The security token could not be authenticated or authorized'', and I do not know how to authorize using security?

I need  simple implementation based python, can you help me?

 

Here is my codes .

Code based python (in linux_centos6.3 64):

#! /usr/bin/python
# -*- coding:utf-8 -*-
import logging
import datetime
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

from suds.client import Client
from suds.plugin import *
from suds.wsse import *
from suds import WebFault


url = "nullhttp://http://10.200.190.2:8080/services/soap/Webservices?wsdl"
client = Client(url)
security = Security()
token = UsernameToken('xuezhe.zhang', 'mypwd')
security.tokens.append(token)
client.set_options(wsse=security)
print client.service.getCardList('Building')

 

The responses:

 <soap:Envelope xmlns:soap="nullhttp://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode xmlns:ns1="nullhttp://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:FailedAuthentication</faultcode><faultstring>The security token could not be authenticated or authorized</faultstring></soap:Fault></soap:Body></soap:Envelope>
Traceback (most recent call last):
  File "cmdb_webservice2.py", line 20, in <module>
    print client.service.getCardList('Building')
  File "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
  File "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line 649, in send
    result = self.failed(binding, e)
  File "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line 702, in failed
    r, p = binding.get_fault(reply)
  File "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/bindings/binding.py", line 265, in get_fault
    raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'The security token could not be authenticated or authorized'

 

Kind regards!
 
yanqu.wu

Hi,

take a look at this thread:
http://www.cmdbuild.org/forum/tecniche/911257777?set_language=en&cl=en
It's in italian language but ... basically our suggestion is to use ZSI.
We created a patched ZSI version avaible here: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/extra/
And you could take a look at the Plone module: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/
And in particular to the ws folder: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/ws/
Other people created working python clients using this code ... hope it helps!  ;)

Greetings

Previously Tecnoteca wrote:

Hi,

take a look at this thread:
http://www.cmdbuild.org/forum/tecniche/911257777?set_language=en&cl=en
It's in italian language but ... basically our suggestion is to use ZSI.
We created a patched ZSI version avaible here: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/extra/
And you could take a look at the Plone module: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/
And in particular to the ws folder: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/ws/
Other people created working python clients using this code ... hope it helps!  ;)

Greetings

 

Hi,
Thank you for the prompt.Follow the prompts.
I patched and  custom ZSI,then run again . I got a "TypeError" error requests.
How can i do?
 
Here's error output.
Traceback (most recent call last):
  File "auth.py", line 64, in <module>
    response = dbfetchSrv.getCardList(request)
  File "/root/plone/tecnoteca.plonecmdbuild/trunk/build/lib/tecnoteca/plonecmdbuild/ws/temp/WebservicesImplService_services.py", line 375, in getCardList
    response = self.binding.Receive('text/xml')
  File "/usr/lib/python2.6/site-packages/ZSI-2.1_a1-py2.6.egg/ZSI/client.py", line 531, in Receive
    self.ReceiveSOAP(**kw)
  File "/usr/lib/python2.6/site-packages/ZSI-2.1_a1-py2.6.egg/ZSI/client.py", line 416, in ReceiveSOAP
    'Response is "%s", not "text/xml"' % self.reply_headers.type)
TypeError: Response is "multipart/related", not "text/xml"
 
Jackey
 

Previously Tecnoteca wrote:

Hi,

take a look at this thread:
http://www.cmdbuild.org/forum/tecniche/911257777?set_language=en&cl=en
It's in italian language but ... basically our suggestion is to use ZSI.
We created a patched ZSI version avaible here: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/extra/
And you could take a look at the Plone module: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/
And in particular to the ws folder: https://svn.plone.org/svn/collective/tecnoteca.plonecmdbuild/trunk/tecnoteca/plonecmdbuild/ws/
Other people created working python clients using this code ... hope it helps!  ;)

Greetings

 

Thank you for the prompt.Follow the prompts.
I patched and  custom ZSI,then run again . I got a "TypeError" error requests.
How can i do?
 
Here's error output.
Traceback (most recent call last):
  File "auth.py", line 64, in <module>
    response = dbfetchSrv.getCardList(request)
  File "/root/plone/tecnoteca.plonecmdbuild/trunk/build/lib/tecnoteca/plonecmdbuild/ws/temp/WebservicesImplService_services.py", line 375, in getCardList
    response = self.binding.Receive('text/xml')
  File "/usr/lib/python2.6/site-packages/ZSI-2.1_a1-py2.6.egg/ZSI/client.py", line 531, in Receive
    self.ReceiveSOAP(**kw)
  File "/usr/lib/python2.6/site-packages/ZSI-2.1_a1-py2.6.egg/ZSI/client.py", line 416, in ReceiveSOAP
    'Response is "%s", not "text/xml"' % self.reply_headers.type)
TypeError: Response is "multipart/related", not "text/xml"
 
Jackey