cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Web Service in Python

kbond
Champ in-the-making
Champ in-the-making
Hello,

I am very impressed by the quality of your young software. Since the begining of the week I fighting in order to use the web service in python.
Unfortunatly I did not manage to be as successfull as I would like.
So far I am able to get my ticket:


from SOAPpy import WSDL, Types,SOAPProxy
alfrescoPassword = "admin"
alfrescoUser = "admin"
wsdlFile = "http://localhost:8080/alfresco/wsdl/authentication-service.wsdl"
server = WSDL.Proxy(wsdlFile)
myTicket=server.startSession(alfrescoUser, alfrescoPassword)

myTicket is now a dictionnary with the following keys: username, ticket

Now the hard piece of the cake is to use it the header of the other calls.
This is where I am stuck however I am almost 100% sure that it is do able since I found some similars examples with:
    + google – http://www.google.com/apis/adwords/python.html
    + microsoft – http://intertwingly.net/stories/2003/09/03/mstop10.py
    + microsoft –http://www.myelin.co.nz/microsoft_com_py/
   
It would be great If someone can help me to get started with this.
Thank you
2 REPLIES 2

kbond
Champ in-the-making
Champ in-the-making
When I try


authoringService = WSDL.Proxy('http://localhost:8080/alfresco/wsdl/authoring-service.wsdl')
I get the following traceback:


—————————————————————————
SOAPpy.wstools.TimeoutSocket.TimeoutError                              Traceback
(most recent call last)

C:\alfresco\custo\webservice\<console>

C:\Python24\Lib\site-packages\SOAPpy\WSDL.py in __init__(self, wsdlsource, confi
g, **kw)
     60             try:
     61                 stream = urllib.urlopen(wsdlsource)
—> 62                 self.wsdl = reader.loadFromStream(stream, wsdlsource)
     63             except (IOError, OSError): pass
     64

C:\Python24\Lib\site-packages\SOAPpy\wstools\WSDLTools.py in loadFromStream(self
, stream, name)
     32         elif hasattr(stream, 'name'):
     33             wsdl.location = stream.name
—> 34         wsdl.load(document)
     35         return wsdl
     36

C:\Python24\Lib\site-packages\SOAPpy\wstools\WSDLTools.py in load(self, document
)
    191                 location = DOM.getAttr(element, 'location')
    192                 location = urllib.basejoin(base_location, location)
–> 193                 self._import(self.document, element, base_location)
    194
    195         #reader = SchemaReader(base_url=self.location)

C:\Python24\Lib\site-packages\SOAPpy\wstools\WSDLTools.py in _import(self, docum
ent, element, base_location)
    296         obimport._loaded = 1
    297
–> 298         importdoc = DOM.loadFromURL(location)
    299         try:
    300             if location.find('#') > -1:

C:\Python24\Lib\site-packages\SOAPpy\wstools\Utility.py in loadFromURL(self, url
)
    607             file = open(url, 'r')
    608         else:
–> 609             file = urlopen(url)
    610
    611         try:

C:\Python24\Lib\site-packages\SOAPpy\wstools\Utility.py in urlopen(url, timeout,
redirects)
    145     conn.putrequest('GET', path)
    146     conn.putheader('Connection', 'close')
–> 147     conn.endheaders()
    148     response = None
    149     while 1:

C:\Python24\lib\httplib.py in endheaders(self)
    792             raise CannotSendHeader()
    793
–> 794         self._send_output()
    795
    796     def request(self, method, url, body=None, headers={}):

C:\Python24\lib\httplib.py in _send_output(self)
    673         msg = "\r\n".join(self._buffer)
    674         del self._buffer[:]
–> 675         self.send(msg)
    676
    677     def putrequest(self, method, url, skip_host=0, skip_accept_encoding=
0):

C:\Python24\lib\httplib.py in send(self, str)
    640         if self.sock is None:
    641             if self.auto_open:
–> 642                 self.connect()
    643             else:
    644                 raise NotConnected()

C:\Python24\Lib\site-packages\SOAPpy\wstools\Utility.py in connect(self)
     96     def connect(self):
     97         self.sock = TimeoutSocket(self.timeout)
—> 98         self.sock.connect((self.host, self.port))
     99
    100

C:\Python24\Lib\site-packages\SOAPpy\wstools\TimeoutSocket.py in connect(self, *
addr)
     72                         return 1
     73                     raise
—> 74         raise TimeoutError('socket connect() timeout.')
     75
     76     def send(self, data, flags=0):

TimeoutError: socket connect() timeout.

The alfresco up and server is running and this page is available: http://localhost:8080/alfresco/wsdl/authoring-service.wsdl

I hope that some one else out there has already solved this issue or found a workaround.
thank you for your help.

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Unfortunately using the web service from Python is not something I have tried yet (I have to admit to not having worked with Python before).

I have, however, successfully connected to the web services from both PHP and Ruby and in both cases it is necessary, once the ticket is acquired, to add the security header to the request.  How you do this in Python I don't know but if it helps I've added the header XML snippet that you are trying to add.



<wss:security>
   <wss:UsernameToken>        
      <wss:Username>userNameValue</wss:Username>
      <wss:Password>ticketValue</wss:Password>
   </wss:UsernameToken>
</wss:security>

where

wss is the namespace http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
userNameValue is the user name
ticketValue is the ticket string


Hope this helps a little.

Roy