cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2444
Views
0
Helpful
8
Replies

CUCM AXL. List Primary Extension.

arnorton1
Level 1
Level 1

Hello,

 

I am trying to get the phone's primary line pattern. I need to get this from the phone itself. As I will not always know what extension might be on the phone. However, I am getting stuck on the syntax.

 

 

phone = 'SEPAABBCCDDEEFF'
phone_data = {'name': phone}
try: phone_resp = service.getPhone(**phone_data) except Fault as err: print("\nZeep error: {0}".format(err)) else: DN_Pattern = phone_resp['return']['phone']['lines']['line']['dirn']['pattern'] print( 'Line 1: {0}'.format( DN_Pattern ))

 

I get the following error.

Traceback (most recent call last):
File "device.py", line 8, in <module>
DN_Pattern = phone_resp['return']['phone']['lines']['line']['dirn']['pattern']
TypeError: list indices must be integers, not str

I can list all the way to DN_Pattern = phone_resp['return']['phone']['lines']['line']. But nothing nested within line.

 

I believe it has to do with the [  after 'line':. I'm not sure how to interpret this.

 

 

    'lines': {
        'line': [
            {
                'index': 1,
                'label': 'Extension 5555',
                'display': 'Extension 5555',
                'dirn': {
                    'pattern': '5555',
                    'routePartitionName': {
'_value_1': 'Partition-PT',

 

 

Any suggestions on what the proper syntax?

Thank You.

 

1 Accepted Solution

Accepted Solutions

dstaudt
Cisco Employee
Cisco Employee

As there can be multiple lines, <line> is going to be represented as an array by Zeep.

Try something like

DN_Pattern = phone_resp['return']['phone']['lines']['line'][0]['dirn']['pattern']

to get the first element of the array.

View solution in original post

8 Replies 8

thedd
Level 1
Level 1

Lets have a look in the Documentation

Within the return ther is phone and the lines part

getPhone_Lines.JPG

 

So it is Return -> Phone -> Lines

 

Within Lines you have any line

 

getPhone_Line.JPG

So it is Return -> Phone -> Lines -> Line

 

And a line itself has dirn -> pattern

So it is Return -> Phone -> Lines -> Line-> dirn -> pattern

 

This would mean your idea is correct.

 

What if you work with the line element itself?


If you only want the primary extension you would even check the index.

 

Maybe try to build a loop and print every Elemet within line.

dstaudt
Cisco Employee
Cisco Employee

As there can be multiple lines, <line> is going to be represented as an array by Zeep.

Try something like

DN_Pattern = phone_resp['return']['phone']['lines']['line'][0]['dirn']['pattern']

to get the first element of the array.

Thank You. This worked.

I'm having an issue in the above referenced scenario where if the phone has multiple lines, the first line data is not being returned as part of the variable assignment, because its not listed first in the dictionary output. It seems that the dictionary output picks a random order for the index and respective line info, resulting in ['lines']['line'][0]['dirn']['pattern'] not always returning the line1 instance. Is there a way to force an ordered output of the lines, based on Index value?

You won't be able to force a particular order from AXL (I'm guessing it probably returns them in index order usually), but you should be able to either sort the result or loop through the result looking for index=1.  This SO thread had some helpful thoughts: https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value

 

I looked at the link you sent over along with several other online references about sorting values within a dictionary and I haven't found a working combination yet. I suspect its in part due to the fact that the phone output is not purely a dictionary set, but also contains square brackets that encapsulate the ['line'] data and are addressable with [0][1][2], etc. I've tried using both the sorted and OrderedDict values to organize the dictionary variable output to a new variable and ordered on 'index', but I keep getting "string indices must be integers" and "RPhone not callable" error messages. Not sure how to dial the syntax in.

Hello,

I running into an error when asking for dirn/pattern for 8861 phones.

My 7965, CIPC, and 8821 return my DN, but no 8861 returns DN.

Using cucm 12.5 and 12.5 wsdl in query

??

b

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: