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

Python, ACI Rest API and https errors.

stevemadel
Level 1
Level 1

I am trying to use the python code located here .  I am running into the following error when I do this.  Does anybody know how to disable this error?

 

/usr/local/lib/python2.7/site-packages/urllib3-1.22-py2.7.egg/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)

6 Replies 6

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

Try adding this to your code:

 

import requests
requests.packages.urllib3.disable_warnings()

 

cheers,

Seb.

Seb Rupik
VIP Alumni
VIP Alumni

...or if that doesn't work filter it via the CLI:

 

 

python -Wignore::InsecureRequestWarning your_script.py

Both of those solutions work for this  code, however when I try and use this  code I get the following error.

 


Traceback (most recent call last):
  File "Development/python-old/ACI/auth.py", line 14, in <module>
    ret = requests.get(url)
  File "/usr/local/lib/python2.7/site-packages/requests-2.18.4-py2.7.egg/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests-2.18.4-py2.7.egg/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests-2.18.4-py2.7.egg/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests-2.18.4-py2.7.egg/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests-2.18.4-py2.7.egg/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='192.168.1.1, port=443): Max retries exceeded with url: /api/node/class/procEntity.xml (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)'),))

I'm not able to view you pastebi source ode for some reason...

 

anyhow you should be able to side step this error by telling requests not to verify the SSL Cert being offered by 192.168.1.1, by adding the parameter verify=False

 

Something like:

response = session.send(request_pr, verify=False)

 

cheers,

Seb.

Here is the code that was added in.  It was added between moDir.login() and moDir.logout()

 

ret = requests.get(url)
ret.staus_code

OK make this change:

ret = requests.get(url, verify=False)

In case you are interested take a look at:

https://github.com/requests/requests/blob/master/requests/sessions.py

 

...starting a line 466. The parameter we are interested in states:

     :param verify: (optional) Either a boolean, in which case it controls whether we verify
            the server's TLS certificate, or a string, in which case it must be a path
            to a CA bundle to use. Defaults to ``True``.

 

cheers,

Seb.

 

 

Review Cisco Networking for a $25 gift card

Save 25% on Day-2 Operations Add-On License