cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1094
Views
0
Helpful
4
Replies

Python axl updateLine - 401

tpaige
Level 1
Level 1

Hello,

Using the cucm GUI, an XML script can be executed against a cucm server,

using the proper credentials for the GUI.

When the same XML is run via a python3.4 script, I always get a 401 authentication error, so
I need some help to figure out what I'm doing wrong.

Here is an example of the python3.4 axl function:

  def axl_call(data):

  encoded=base64.b64encode(bytes(user + ':' + pwd,"utf-8"))

  header ={

               'Content-type' : 'text/xml',

              'SOAPAction' : 'CUCM:DB ver=8.5 UpdateLine',

              'Authorization' : "Basic %s" % encoded

             }

  print (header)

  url = 'https://'+ip+':8443/axl/'

  print ('Before post...')

  r = requests.post(url,headers=header,data=data,verify=False)

  print ('After post...')

  if (r.status_code == requests.codes.ok):

  print (str(r.status_code) + ' OK')

  else:

  print ('****************************')

  print ('YOU MADE A MISTAKE SOMEWHERE')

  print (str(r.status_code))

  return

I always get the 'YOU MADE A MISTAKE SOMEWHERE' msg and the status code is always a 401.

Now, I have also tried this method:

header ={

               'Content-type' : 'text/xml',

               'SOAPAction' : 'CUCM:DB ver=8.5 UpdateLine',

             }

  print (header)

  url = 'https://'+ip+':8443/axl/'

  print ('Before post...')

  r = requests.post(url,headers=header,data=data,verify=False, auth=(user,pwd))

But this version does not work either.

So, I'm missing some key information about how to authenticate via a python, axl script.

Any help or suggestions would be appreciated.

Here is the XML:

<?xml version="1.0" ?>

<soapenv:Envelope xmlns:ns="http://www.cisco.com/AXL/API/8.5" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelop/">

  <soapenv:Header/>

     <soapenv:Body>

       <ns:updateLine sequence="?">

       <pattern>85309215</pattern>

       <callForwardAll>

         <destination>85309452</destination>

       </callForwardAll>

    </ns:updateLine>

  </soapenv:Body>

</soapenv:Envelope>

4 Replies 4

m.batts
Level 4
Level 4

This is mine for 10.5 which works

headers= {'Content-Type': 'text/xml',
          'SOAPAction': 'CUCM:DB ver=10.5 updateLine'}

xml="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.5">
            <soapenv:Header/>
            <soapenv:Body>
            <ns:updateLine sequence="1">
                <pattern>1183717</pattern>
    <routePartitionName>Full_access</routePartitionName>
    <newPattern>1183719</newPattern>
            </ns:updateLine>
       <soapenv:Body>
     </soapenv:Envelope>"""

Hi Mark,

Thanks for responding!

Some questions:

1. Does it matter what the sequence value on the ns:updateLine is?

I see you are using "1", while I'm using "?".

2. Are you executing that XML in the cucm GUI or are you using Python?

If you're using Python, can I see your request statement.

I'm asking because I think I'm having an authentication problem since I always get a

401 back.

When we send the XML request in via the GUI, it always works.

3. I take it it does not matter that we are using 8.5. I'm pretty sure we have 10.5 installed,

but we were just trying to get this script to work. The code we are using should be fine for 8.5.

We have a script like that already. It works great but we are looking to scale that to call forward hundreds of numbers referenced in a text files.

It looks like the implicit converstion from bytes[] to string in your header string format didn't work as expected.  The below works for me explicitly decoding the base64 bytes output to utf-8:

import requests

import base64

encoded = base64.b64encode(bytes('administrator:ciscopsdt', "utf-8"))

header = {

    'Content-type': 'text/xml',

    'SOAPAction': 'CUCM:DB ver=10.5 UpdateLine',

    'Authorization': 'Basic %s' % encoded.decode('utf-8')

}

data = '''

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

    xmlns:ns="http://www.cisco.com/AXL/API/10.5">

  <soapenv:Header/>

  <soapenv:Body>

      <ns:getUser>

        <userid>dstaudt</userid>

      </ns:getUser>

  </soapenv:Body>

</soapenv:Envelope>

'''

print(header)

url = 'https://ds-ucm105.cisco.com:8443/axl/'

r = requests.post(url, headers=header, data=data, verify=False)

print (r.text)