cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1047
Views
1
Helpful
9
Replies

CUCM AXL API 12.5 - Unable to retrieve a response using python post

pethuraja
Level 1
Level 1

Hi Guys,

I am new to CUCM AXL API and I was referring the Cisco Dev guide for creating/automating the IP phone/softphone configuration.

In the initial steps I used GET to interact with AXL API and the response code was [200]. While accessing the AXL code via POST with an XML payload (https) it shows [401] error and response code as [300] using normal http. The creds are correct, I am unable to figure out the error. One additional info is the site is not secure as the creds are not configured for this test server.

The post is not getting me the XML response it is getting me the html response of the page. (Refer attached images)

 

import requests
from requests.auth import HTTPBasicAuth
import base64
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import xml.etree.ElementTree as ET
import xmltodict


# SOAP request URL


#url = "http://doamin-Name/axl"
url1 = "https://doamin-Name:8443/axl/"


# structured XML
payload ="""<?xml version ="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/12.5">
<soapenv:Header/>
<soapenv:Body>
<ns:getCCMVersion>
</ns:getCCMVersion>
</soapenv:Body>
</soapenv:Envelope>"""


# headers
headers1 = {
'Content-Type': 'text/xml;charset=utf-8',
'SOAPAction': 'CUCM:DB ver=12.5 getCCMVersion',
'Authorization': 'Basic passw'
}


resp = requests.post(url1, verify=False,auth = ('user','passws'), headers=headers1, data = payload, stream = True,timeout=50)

print(resp.content)

events = ET.iterparse(resp.raw)

#for event, elem in events:
# print(event, elem)

print(resp.content)

print(resp.history)
print(resp.headers)
print(resp.request.headers)
c= resp.cookies
print("Cookies : ",c)

9 Replies 9

Alexander Stevenson
Cisco Employee
Cisco Employee

@pethuraja 

Thanks for sharing the details. Which sandbox exactly are you using for this?

It looks like you're using a Python file. Have you tried running the POST request from Postman?

Postman is not permitted to be used in our system. I am using a python from Visual studio to get the task done instead of using postman. I am not sure what a sandbox is actually. I am actually getting the webpage's html response instead of the xml response as mentioned in dev guide

I have managed to install postman in my machine, Post request gave 401 error - attaching the response image. Please have a look into it.

Alexander Stevenson
Cisco Employee
Cisco Employee

Hi @pethuraja,

 

In the Authorization header, you must provide the base64 format of username/password. That can be generated with something like so:

credentials = f"{user}:{passws}"
encoded_credentials = base64.b64encode(credentials.encode()).decode()

 

It also seems you should implement variables like so:

headers1 = {
'Content-Type': 'text/xml;charset=utf-8',
'SOAPAction': 'CUCM:DB ver=12.5 getCCMVersion',
'Authorization': f'Basic {encoded_credentials}'
}

# Use the correct variables for authentication
resp = requests.post(url1, verify=False, auth=(user, passws), headers=headers1, data=payload, stream=True, timeout=50)

 

Also make sure the variable names are consistent. You have both passws and passw

 

Hi @Alexander Stevenson ,

Tried the method of encoding the creds in headers and verified the values of the variables as well prior to raising the question in dev hub. But still it fails!. Please review the attached image as it says the test server is running in evaluation mode and is unregistered, Will this affect the API calls? and I am unable to SSH the server as well with the api creds

 

Marcel Zehnder
Spotlight
Spotlight

Hi
If you use requests auth parameter you don't need to set the authentication header (requests will handle the base64 encoding).

import requests

username = "youruser"
password = "yourpassword"
server = "yourserver"

url = f"https://{server}:8443/axl"

headers = {
    "Content-Type": "text/xml;charset=UTF-8",
    "SOAPAction": "CUCM:DB ver=12.5 getCCMVersion"
}

payload = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/12.5">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:getCCMVersion>
         <processNodeName></processNodeName>
      </ns:getCCMVersion>
   </soapenv:Body>
</soapenv:Envelope>
"""

r = requests.post(url=url, verify=False, auth=(username,password), headers=headers, data=payload)
print(r.status_code)
print(r.text)

Hi @Marcel Zehnder ,

I have tried the same, I think in the url you are missing a "/" at the end as it would move into the axl service. The code marcel shared give me the html response for the post method instead of the xml object. Adding the response text's images below.

The missing "/" is possible, I don't have access to a real API and my post is based on the doc/examples I found on devnet. If you add the "/" and add print statements for content and/or raw, you still get the HTML response I guess?

print(r.content)
print(r.raw)

 

 

Alexander Stevenson
Cisco Employee
Cisco Employee

@pethuraja I have a feeling you're close to solving this. Try Marcel's suggestion above (no encoding needed).