01-03-2020 05:44 PM
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.
Solved! Go to Solution.
01-06-2020 07:24 AM
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.
01-06-2020 12:44 AM
Lets have a look in the Documentation
Within the return ther is phone and the lines part
So it is Return -> Phone -> Lines
Within Lines you have any line
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.
01-06-2020 07:24 AM
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.
01-21-2020 12:37 PM
05-20-2020 06:43 AM
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?
05-20-2020 08:11 AM
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
05-20-2020 01:16 PM
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.
12-16-2021 08:16 AM
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
12-16-2021 12:20 PM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide