09-12-2023 07:31 AM
I was using restconf code on a cisco IOS-XE router (dist-rtr02) in the pre-built sample network. I'm wondering if I got a status code of 502 because of a firewall issue.
Solved! Go to Solution.
09-12-2023 09:54 PM - edited 09-13-2023 01:58 AM
When I ran my python code the first time, I was getting a HTTPS status code of 502. I'm not sure why this happened but when I tried again it worked. What I noticed was RESTCONF was not enabled on the router by default. I had to configure the router to use it. They probably omitted that configuration when they upgraded the version of CML to 2.5.1.
09-12-2023 08:25 AM
Did you enable RESTCONF correct on the router (see https://developer.cisco.com/docs/ios-xe/#!enabling-restconf-on-ios-xe), 502 is not an error code used by RESTCONF, might be not correctly enabled.
Also, can you post your RESTCONF endpoint, headers and payload?
09-12-2023 01:42 PM
Here's a sample of my code:
# Router details
router_ip = '10.10.20.176'
username = 'cisco'
password = 'cisco'
interface_name = 'GigabitEthernet=1'
# API endpoint for native interface JSON output
api_endpoint = f"https://{router_ip}/restconf/data/Cisco-IOS-XE-native:native/interface/{interface_name}/ip/address/primary"
# Request headers
headers = {
'Accept': 'application/yang-data+json',
'Content-Type': 'application/yang-data+json'
}
# Authentication credentials
auth = (username, password)
# Make the request
response = requests.get(api_endpoint, headers=headers, auth=auth, verify=False)
Hope this helps.
09-12-2023 09:06 PM
Ok folks, I tried it again and I got it to work. Here's a look at the JSON data I got:
{
"Cisco-IOS-XE-native:primary": {
"address": "10.10.20.176",
"mask": "255.255.255.0"
}
}
Thanks for your assistance.
09-12-2023 09:35 PM
What was the issue, how did you solve it?
09-12-2023 09:54 PM - edited 09-13-2023 01:58 AM
When I ran my python code the first time, I was getting a HTTPS status code of 502. I'm not sure why this happened but when I tried again it worked. What I noticed was RESTCONF was not enabled on the router by default. I had to configure the router to use it. They probably omitted that configuration when they upgraded the version of CML to 2.5.1.
09-12-2023 10:51 PM
Okay, that's what I thought, glad it works now.
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