#!/usr/bin/env python import xml.etree.ElementTree as ET import requests url = 'https://:7071/service/admin/soap' headers = { 'Content-Type': 'application/soap+xml' } # Get the credentials through zmlocalconfig # zmlocalconfig zimbra_user # zmlocalconfig -s zimbra_ldap_password zimbra_user = 'zimbra' zimbra_password = '' token_xml = '\ \ %s%s' % (zimbra_user, zimbra_password) r = requests.post(url, data=token_xml, headers=headers) # Got the admin token, now you can get the delegated token to act on behalf a specific account admin_token = ET.fromstring(r.content).find('.//{urn:zimbraAdmin}authToken').text username_to_act_on_behalf = 'sandro.mello@inova.net' delegated_token_xml = '\ %s\ %s' % (admin_token, username_to_act_on_behalf) r = requests.post(url, data=delegated_token_xml, headers=headers) delegated_token = ET.fromstring(r.content).find('.//{urn:zimbraAdmin}authToken').text info_request_xml = '\ %s%s\ \ ' % (delegated_token, username_to_act_on_behalf) # Now you can start using the main url main_url = 'https:///service/soap' r = requests.post(main_url, data=info_request_xml, headers=headers) print(r.content)