10-11-2019 05:50 AM
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.
10-11-2019 06:48 AM
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.
10-11-2019 06:53 AM
10-11-2019 07:04 AM
Do you have to go through a web proxy to reach the APIC server?
10-11-2019 07:26 AM
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