cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
915
Views
0
Helpful
4
Replies

Cisco APIC Rest API Issues

justintaylor9
Level 1
Level 1

Need some help with my APIC REST API connection ... this part of the documentation is throwing me off ...

 

Their payloads contain a simple XML or JSON payload containing the MO representation of an aaaUser object with the attribute name and pwd defining the username and password: for example, <aaaUser name='admin' pwd='password'/>. The response to the POST operation will contain an authentication token as both a Set-Cookie header and an attribute to the aaaLogin object in the response named token, for which the XPath is /imdata/aaaLogin/@token if the encoding is XML. Subsequent operations on the REST API can use this token value as a cookie named APIC-cookie to authenticate future requests.

 

My code so far:

 

#!/usr/bin/python

import json
import requests

# setup connection parameters
apic_ip = "10.6.221.10"

# JSON Payload
payload = {"username":"username","password":"password"}

# GET Request
url = 'https://10.6.221.10/api/v1/ticket'
header = {"content-type":"application/json"}
response = requests.post(url, data=json.dumps(payload), headers=header, verify=False)
print(response.text)

 

I continuously get "No route to host". Any help is appreciated.

 

 

4 Replies 4

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

I hate to ask it, but can you actually ping the IP 10.6.221.10 from the device you are running the script from?

 

Maybe adjust the script and try to catch the error:

#!/usr/bin/python
import json
import requests
# setup connection parameters
apic_ip = "10.6.221.10"
# JSON Payload
payload = {"username":"username","password":"password"}
# GET Request
url = "https://{0}/api/v1/ticket".format(apic_ip)
header = {"content-type":"application/json"}
try:
    response = requests.post(url, data=json.dumps(payload), headers=header, verify=False)
except requests.exceptions.ConnectionError as e:
    print(e.args)

if response is not None:
        print json.loads(response.text)

cheers,

Seb.

justintaylor9
Level 1
Level 1
Yes the IP is pingable. I tried the update to the code and the result is the same:



Traceback (most recent call last):

File "./api-connect.py", line 17, in

response = requests.post(url, data=json.dumps(payload), headers=header, verify=False)

File "/usr/lib/python2.6/site-packages/requests/api.py", line 108, in post

return request('post', url, data=data, json=json, **kwargs)

File "/usr/lib/python2.6/site-packages/requests/api.py", line 50, in request

response = session.request(method=method, url=url, **kwargs)

File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 464, in request

resp = self.send(prep, **send_kwargs)

File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 576, in send

r = adapter.send(request, **kwargs)

File "/usr/lib/python2.6/site-packages/requests/adapters.py", line 415, in send

raise ConnectionError(err, request=request)

requests.exceptions.ConnectionError: ('Connection aborted.', error(113, 'No route to host'))


Do you have to go through a web proxy to reach the APIC server?

Nope not going through a web proxy.


Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: