08-14-2023 02:05 AM
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)
08-14-2023 11:26 AM
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?
08-15-2023 10:58 PM
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
08-16-2023 05:54 AM
08-17-2023 07:36 AM
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
08-20-2023 10:35 PM - edited 08-20-2023 10:36 PM
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
08-20-2023 11:28 PM
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)
08-21-2023 05:45 AM
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.
08-21-2023 07:50 AM
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)
08-21-2023 05:07 AM
@pethuraja I have a feeling you're close to solving this. Try Marcel's suggestion above (no encoding needed).
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