Results 1 to 10 of 10

Thread: Python-Library to access Zimbra SOAP API

  1. #1
    ploeger's Avatar
    ploeger is offline Senior Member
    Join Date
    Oct 2008
    Posts
    74
    Rep Power
    6

    Lightbulb Python-Library to access Zimbra SOAP API

    Hi everybody!

    If you're a python developer and work using the Zimbra SOAP API, there are common tasks that are done every time: Build up requests in XML or JSON format, create an authentication request, add the token to other requests...

    To simplify this, there's now a python library to simply access the SOAP API. Check it out on pypi as python-zimbra (prereleased currently) or at

    https://github.com/Zimbra-Community/python-zimbra

    Please check it out and report problems to the issue tracker at github.

    Thanks.

    Kind regards
    Dennis
    Release 8.0.6.GA.5922.UBUNTU12.64 UBUNTU12_64 NETWORK edition.

  2. #2
    ploeger's Avatar
    ploeger is offline Senior Member
    Join Date
    Oct 2008
    Posts
    74
    Rep Power
    6

    Default

    Just a quick note, that Version 1.0-rc2 has been released adding the missing support for multiple items in XML-requests.
    Release 8.0.6.GA.5922.UBUNTU12.64 UBUNTU12_64 NETWORK edition.

  3. #3
    yutaka is offline Project Contributor
    Join Date
    Oct 2009
    Location
    Tokyo
    Posts
    113
    Rep Power
    5

    Default

    Awesome!

  4. #4
    lavaud is offline Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Rep Power
    1

    Default

    hi,


    I have installed and successfullly used pythonzimbra api with the example given.

    I'd like to go further and send requests with parameters.

    And here I'm stuck...

    The idea would be to send a GetAccountInfoRequest request searching by name.


    Do you have a little example code to help me or a link ?


    Many thanks.

  5. #5
    lavaud is offline Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Rep Power
    1

    Default

    The source code :

    #! /usr/bin/python
    # -*- coding: utf-8 -*-

    import urllib2

    from pythonzimbra.tools import auth, xmlserializer
    from pythonzimbra.request_xml import RequestXml
    from pythonzimbra.response_xml import ResponseXml
    from pythonzimbra.communication import Communication

    from pythonzimbra.tools import xmlserializer
    from xml.dom import minidom
    from pythonzimbra.tools.xmlserializer import dom_to_dict

    SOAP_URL="https://server.u-bordeaux.fr:7071/service/admin/soap"
    PRE_AUTH_KEY="..."
    SOAP_USER="..."

    def my_dom2_to_dict():
    test_doc = minidom.Document()

    test_node = test_doc.createElement("account")

    test_node.setAttribute("by", "name")

    test_node.appendChild(test_doc.createTextNode("use rname@u-bordeaux.fr"))

    test_doc.appendChild(test_node)

    test_dict = dom_to_dict(test_node)

    return test_dict


    def main():

    comm = Communication(SOAP_URL)

    token = auth.authenticate(SOAP_URL, SOAP_USER, PRE_AUTH_KEY)

    info_request = RequestXml()

    info_request.set_auth_token(token)

    le_dico = my_dom2_to_dict()

    info_request.add_request('GetAccountInfoRequest', le_dico, 'urn:zimbraAdmin')

    info_response = ResponseXml()

    try:
    comm.send_request(info_request, info_response)
    except urllib2.HTTPError, error:
    contents = error.read()

    if not info_response.is_fault():
    print info_response.get_response()

    if __name__ == "__main__":
    main()





    The result:

    Traceback (most recent call last):
    File "modify_account.py", line 118, in <module>
    main()
    File "modify_account.py", line 114, in main
    if not info_response.is_fault():
    File "/usr/lib/python2.6/site-packages/python_zimbra-1.0_rc5-py2.6.egg/pythonzimbra/response.py", line 99, in is_fault
    if self.is_batch():
    File "/usr/lib/python2.6/site-packages/python_zimbra-1.0_rc5-py2.6.egg/pythonzimbra/response_xml.py", line 36, in is_batch
    if self.response_doc.getElementsByTagName("BatchRespo nse").length > 0:
    AttributeError: 'NoneType' object has no attribute 'getElementsByTagName'

    Zimbra version :
    Release 8.0.6_GA_5922.RHEL6_64_20131203103753 RHEL6_64 NETWORK edition.

  6. #6
    ploeger's Avatar
    ploeger is offline Senior Member
    Join Date
    Oct 2008
    Posts
    74
    Rep Power
    6

    Default

    Hi!

    Hmmm... though I find your way of converting a dom into a dict as opposed to not directly working on a dict rather strange, it should work.

    Could you please have a look in your mailbox.log on the Zimbra server. I think, that there's an exception thrown when you run your code.

    Kind regards
    Dennis
    Release 8.0.6.GA.5922.UBUNTU12.64 UBUNTU12_64 NETWORK edition.

  7. #7
    lavaud is offline Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Rep Power
    1

    Default Solved my problem

    Quote Originally Posted by ploeger View Post
    Hi!

    Hmmm... though I find your way of converting a dom into a dict as opposed to not directly working on a dict rather strange, it should work.

    Could you please have a look in your mailbox.log on the Zimbra server. I think, that there's an exception thrown when you run your code.

    Kind regards
    Dennis
    Thank you !

    I used the wrong authentication method !

    The good one was : "Authentication against the administration console".

    And of course, the log helped me... even if I looked at it yesterday. Certainly too late

  8. #8
    lavaud is offline Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Rep Power
    1

    Default fall back to zimbra default auth mechanism

    My problem was solved by I see this in the logs :

    2014-03-26 17:39:27,910 WARN [qtp310912546-84420:https://the_server.u-bordeaux.fr:707...ce/admin/soap] [name=superuser@u-bordeaux.fr;ip=the_ip;] account - ldap auth for domain u-bordeaux.fr failed, fall back to zimbra default auth mechanism

    and an uggly java exception jus after...

    Why ?

  9. #9
    ploeger's Avatar
    ploeger is offline Senior Member
    Join Date
    Oct 2008
    Posts
    74
    Rep Power
    6

    Default

    Quote Originally Posted by lavaud View Post
    2014-03-26 17:39:27,910 WARN [qtp310912546-84420:https://the_server.u-bordeaux.fr:707...ce/admin/soap] [name=superuser@u-bordeaux.fr;ip=the_ip;] account - ldap auth for domain u-bordeaux.fr failed, fall back to zimbra default auth mechanism
    It seems, that you're using an external LDAP server (Active Directory?) for authentication in the u-bordeaux.fr-domain with a fallback to the internal Zimbra auth database. And it seems, it did fail when you tried to authenticate superuser@u-bordeaux.fr. Probably because this administrative account doesn't exist in your external LDAP server.

    Kind regards
    Dennis
    Release 8.0.6.GA.5922.UBUNTU12.64 UBUNTU12_64 NETWORK edition.

  10. #10
    lavaud is offline Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Rep Power
    1

    Default understood

    Quote Originally Posted by ploeger View Post
    It seems, that you're using an external LDAP server (Active Directory?) for authentication in the u-bordeaux.fr-domain with a fallback to the internal Zimbra auth database. And it seems, it did fail when you tried to authenticate superuser@u-bordeaux.fr. Probably because this administrative account doesn't exist in your external LDAP server.

    Kind regards
    Dennis
    That's it, not an external ldap server but a cas (sso) server.

    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. zcs-php - yet another PHP SOAP API library
    By gionn in forum Developers
    Replies: 9
    Last Post: 12-12-2013, 12:29 PM
  2. Perl Module to simplify SOAP access to Zimbra
    By crankin in forum Developers
    Replies: 22
    Last Post: 08-07-2012, 05:14 AM
  3. access zimbra from java using soap
    By aldm in forum Developers
    Replies: 2
    Last Post: 02-20-2011, 05:37 PM
  4. Zimbra SOAP Access from Java
    By 3RiversTechAdmin in forum Developers
    Replies: 8
    Last Post: 09-03-2008, 07:24 AM
  5. [SOLVED] SOAP access to the Zimbra server
    By sahuguet in forum Developers
    Replies: 29
    Last Post: 04-10-2008, 07:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •