CiscoDevNet/netprog_basics

Help with Python Part 3 request.get Access Denied Why ?

Closed this issue · 1 comments

I am learning the lesson in Python Part3 trying to use the request.get

Now in the video he uses 10.10.20.21 however in the info for the lesson it say to reference the always on sandbox. The router ther has an ip address of 10.10.20.48 so this is the ip address I've used. so i enter all the correct info and get the cert warning, which i expect, but when I run the print command to get the interface info I'm getting errors for access denied and protocol, why is this ?

Firstly you can see i make it as far as the router as i get a cert warning regarding the self certs

router = {“ip”: “10.10.20.48” ,
… “port”:“443”,
… “user”:“XXXX”,
… “pass”:“XXXXX”}

headers = {“Accept”: “application/yang-data+json”}
u = “https://{}:{}/restconf/data/interfaces/interface=Gigabitethernet1”
u = u.format(router[“ip”], router[“port”])
print(u)
https://10.10.20.48:443/restconf/data/interfaces/interface=Gigabitethernet1

r = requests.get(u,
… headers = headers,
… auth=(router[“user”], router[“pass”]),
… verify=False)
C:\Users\M7551873\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host ‘10.10.20.48’.
Adding certificate verification is strongly advised. See: Advanced Usage - urllib3 2.0.0.dev0 documentation

I then run pprint and expect it to return the interface information but i get access denied. I expect this is because I’m being given the wrong credentials? Or is it the request headers? this is what i get when running the print command

pprint(r.text)
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘pprint’ is not defined

from pprint import pprint
pprint(r.text)
(’{\n’
’ “errors”: {\n’
’ “error”: [\n’
’ {\n’
’ “error-tag”: “access-denied”,\n’
’ “error-type”: “protocol”\n’
’ }\n’
’ ]\n’
’ }\n’
‘}\n’)

print(r.text)
{
“errors”: {
“error”: [
{
“error-tag”: “access-denied”,
“error-type”: “protocol”
}
]
}
}

added a more detailed entry