cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
568
Views
0
Helpful
6
Replies

I'm unable to get data from restconf in the CML devnet sandbox

acherubin
Level 1
Level 1

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.

1 Accepted Solution

Accepted Solutions

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.

View solution in original post

6 Replies 6

Marcel Zehnder
Spotlight
Spotlight

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?

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.

 

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.

Marcel Zehnder
Spotlight
Spotlight

What was the issue, how did you solve it?

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.

Marcel Zehnder
Spotlight
Spotlight

Okay, that's what I thought, glad it works now.