08-06-2021 06:43 AM
Just about at the end of my wits here. Simply trying to make a successful API call to my csr1000v in my cisco CML 2.0 environment.
When I make the call, I get this message in the console which seems to indicate that I was authenticated
*Aug 6 13:23:05.775: %DMI-5-AUTH_PASSED: R0/0: dmiauthd: User 'cisco' authenticated successfully from 192.168.0.5:0 and was authorized for rest over http. External groups: PRIV01
However, what I get back in postman or when I run my python script is this:
Router1#show run
Building configuration...
hostname Router1
!
boot-start-marker
boot-end-marker
!
!
enable password cisco
!
no aaa new-model
!
crypto pki trustpoint TP-self-signed-213311658
enrollment selfsigned
subject-name cn=IOS-Self-Signed-Certificate-213311658
revocation-check none
rsakeypair TP-self-signed-213311658
!
!
crypto pki certificate chain SLA-TrustPoint
certificate ca 01
...
1
quit
crypto pki certificate chain TP-self-signed-213311658
certificate self-signed 01
license udi pid CSR1000V sn 9VGN5HCJY3E
diagnostic bootup level minimal
!
!
restconf
!
username cisco password 0 cisco
!
redundancy
line con 0
logging synchronous
stopbits 1
line vty 0 4
login local
transport input telnet
My python script:
Solved! Go to Solution.
08-07-2021 06:20 AM
@MapleMagician on your device you should only need
username admin privilege 15 secret admin ! ip http secure-server ! restconf
I haven't tried to use DHCP on a management interface before and typically have hard coded IP addresses on my interface.
Try this test/code (update with your own router details or just run this against the devnet always on sandbox)
If this does not work, the test RESTCONF server is up and running with a curl test.
(venv) $ curl -k https://sandbox-iosxe-latest-1.cisco.com/restconf/ -u "developer:C1sco12345" <restconf xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"> <data/> <operations/> <yang-library-version>2016-06-21</yang-library-version> </restconf>
Or
curl -k https://sandbox-iosxe-latest-1.cisco.com/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=GigabitEthernet1 -u "developer:C1sco12345"
import requests import sys HOST = 'sandbox-iosxe-latest-1.cisco.com' USER = 'developer' PASS = 'C1sco12345' requests.packages.urllib3.disable_warnings() # set REST API headers headers = { "Accept": "application/yang-data+json", "Content-Type": "application/yang-data+json", } url = f"https://{HOST}/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=GigabitEthernet1" # print(url) response = requests.get(url, auth=(USER, PASS),headers=headers, verify=False) print(response.text)
08-07-2021 06:20 AM
@MapleMagician on your device you should only need
username admin privilege 15 secret admin ! ip http secure-server ! restconf
I haven't tried to use DHCP on a management interface before and typically have hard coded IP addresses on my interface.
Try this test/code (update with your own router details or just run this against the devnet always on sandbox)
If this does not work, the test RESTCONF server is up and running with a curl test.
(venv) $ curl -k https://sandbox-iosxe-latest-1.cisco.com/restconf/ -u "developer:C1sco12345" <restconf xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"> <data/> <operations/> <yang-library-version>2016-06-21</yang-library-version> </restconf>
Or
curl -k https://sandbox-iosxe-latest-1.cisco.com/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=GigabitEthernet1 -u "developer:C1sco12345"
import requests import sys HOST = 'sandbox-iosxe-latest-1.cisco.com' USER = 'developer' PASS = 'C1sco12345' requests.packages.urllib3.disable_warnings() # set REST API headers headers = { "Accept": "application/yang-data+json", "Content-Type": "application/yang-data+json", } url = f"https://{HOST}/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=GigabitEthernet1" # print(url) response = requests.get(url, auth=(USER, PASS),headers=headers, verify=False) print(response.text)
08-08-2021 10:31 AM
It works! I'm still not even entirely sure what I did wrong but I wiped the router and put in the bare minimum config that you mentioned and it worked. Thanks a lot!
08-08-2021 11:07 AM
awesome @MapleMagician i think i saw something like this before - when you had to remove restconf section of the config and add it back in - anyhoo - glad its working!
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