Use Python to connect to Cisco Unified Communications Manager

2 minute read

To connect to CUCM using Python, you need use the Cisco AXL Toolkit and Zeep, a Python SOAP Client.

Zeep will inspect a WSDL document and generate the code to use the services and types in the document. This makes it easy to interface with the SOAP server.

You can install Zeep using pip, assuming you have pip installed: pip install zeep

Get the CiscoAXL Toolkit

In order to connect to to CUCM using Python,you need to have some files from the AXL Toolkit. You can download this from your CUCM instance.

  • Log into CUCM
  • Select Application > Plugins
  • Click Find to list all available plugins
  • Look for Cisco AXL Toolkit and click the Download link on the left
  • save the ZIP file to your local machine

Extract the files from the ZIP

There are 3 files need from the ZIP, you can find them in the schema folder. The current folder will have the files that match the version of CUCM you have installed. If you need a version that is different from the currently installed version, use the files from the folder that matches the version of CUCM that you intend to attach to.

AXL Toolkit Schema Filelist

Extract the files to a place that your Python script will be able to access.

Make sure your CUCM user has access to the AXL API

Your user (preferablly an application user), will need to have one of the following roles assigned in order to make the connection using AXL.

  • Standard AXL API Access [Allows Access to the AXL database API], this has read/write access using the AXL API
  • Standard AXL API Users [Grants login rights to execute AXL APIs]
  • Standard AXL Read Only API Access [Allows access to the read only API’s] Read only API’s include list APIs, get APIs and executeSQLQuery API

NOTE: The Standard AXL API Access is by default associated with the Standard CCM Super Users Access Control Group

Python Packages

You need the following packages to make the AXL connection to CUCM:

  • requests
  • zeep
  • urllib3

You can install zeep using pip, which installs urllib3 as part of the package

Python Variables

  • WSDL_URI : This is the file URI to the AXL toolkit schema AXLAPI.wsdl file. (file://d:/axlsqltoolkit/schema/current/AXLAPI.wsdl)
  • CUCM_USERNAME : Account name with AXL Access
  • CUCM_PASSWD : Password for CUCM Account
  • CUCM_URL : URL to AXL entrypoint of CUCM (https://ipaddress:8443/axl)

Connect to CUCM with Python

from requests import Session
from requests.auth import HTTPBasicAuth
from zeep import Client
from zeep.transports import Transport
from zeep.cache import SqliteCache
import urllib3

WSDL_URI = 'file://d:/axlsqltoolkit/schema/current/AXLAPI.wsdl'
CUCM_USERNAME = 'AccountUser'
CUCM_PASSWD = 'password'
CUCM_URL = 'https://127.0.0.1:8443/axl/'

#Connect to CUCM
# disable Insecure Request Warning due to Verify
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

session = Session()
session.verify = False
session.auth = HTTPBasicAuth(CUCM_USERNAME, CUCM_PASSWD)
transport = Transport(session=session, timeout=10, cache=SqliteCache())

client = Client(WSDL_URL, transport=transport)
service = client.create_service("{http://www.cisco.com/AXLAPIService/}AXLAPIBinding", CUCM_URL)

#Verify that you made the connection and can access the APIs

service.getCCMVersion()

If you get back a response with the CUCM Version, then you are all good

{
    'return': {
        'componentVersion': {
            'version': '12.5.1.12900(115)'
        }
    },
    'sequence': None
}

If you are getting errors there are a few simple things to check:

  1. Is the WSDL_URL formatted correctly?
    • If using Path.as_uri() , it outputs the URI as “file:///…” and this caused errors with the client connection
    • Try using "file://d:/path/to/axltoolkit/AXLAPI.wsdl" and hard code the variable without trying to build the file uri programmatically
    • To build the path relative to the python script directory use the following (this works well for python on windows)
      from pathlib import Path
      WSDL_URL = 'file://' + Path("subdir/AXLAPI.wsdl").absolute().as_posix()
      
  2. Does your CUCM_USERNAME have access to the AXL API?