02-09-2022 05:22 PM
Please help!
I'm executing a Python script (on Sublime Text), on my desktop, to make an API call to a Nexus Switch, in a Sandbox Lab and I'm getting this error:
"requests.exceptions.SSLError: HTTPSConnectionPool(host='sbx-nxos-mgmt.cisco.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)"
How do I get around this? I do have the correct admin credentials because I can access the NX-API Sandbox on a browser, although I need to circumvent a certificate warning every time.
02-09-2022 08:02 PM
Hi,
you can avoid verification of certificates like below.
response = session.send(request_pr, verify=False)
check this thread
https://community.cisco.com/t5/application-centric/python-aci-rest-api-and-https-errors/td-p/3786181
02-10-2022 02:24 PM
I appreciate the reply, but unfortunately, it did not work.
I did try other methods but I keep getting this error:
"InsecureRequestWarning: Unverified HTTPS request is being made to host 'sbx-nxos-mgmt.cisco.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings"
So I have a feeling there's no way around it. Or maybe I haven't explored all options.
02-11-2022 12:02 AM
@Riff Raf could you share your code?
02-14-2022 02:37 PM
import json import requests from requests.auth import HTTPBasicAuth if __name__ == "__main__": auth = HTTPBasicAuth('admin', 'Admin_1234!') headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } url = 'https://sbx-nxos-mgmt.cisco.com' payload = { "ins_api": { "version": "1.0", "type": "cli_show", "chunk": "0", "sid": "1", "input": 'show version', "output_format": "json" } } response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth) print(response)
02-14-2022 09:33 PM
HI @Riff Raf
You are missing this part:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
Stay safe,
Sergiu
02-24-2022 08:20 AM
Thanks Sergiu.
The code you shared suppressed the warning but what really allowed my code to run--I discovered-- was the addition of the "verify=False" argument in the call.
I appreciate everybody's help!
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