cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1637
Views
0
Helpful
6
Replies

"certificate verify failed" on Python API call to Nexus Switch

Riff Raf
Level 1
Level 1

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.

6 Replies 6

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 

Please rate this and mark as solution/answer, if this resolved your issue
Good luck
KB

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.

@Riff Raf could you share your code?

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

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)

HI @Riff Raf 

 

You are missing this part:

from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

 

Stay safe,

Sergiu

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.

 

 

Screen Shot .png

 

I appreciate everybody's help!