finish06 / pyunifi

https://unifi-sdn.ubnt.com/
MIT License
223 stars 99 forks source link

ssl_verify issues #54

Closed shanelord01 closed 3 years ago

shanelord01 commented 4 years ago

Hi,

Trying to modify an old script.

I have an argument set as:

parser.add_argument('-s', '--sslCert', help = "SSL CertPath True or False", default = "False")

and parse the argument as below:

if args.sslcert is not None:
    sslCert = args.sslcert
else:
    sslCert = os.getenv("SSL_CERT_VAR")
    if sslCert is None:
        sslCert = raw_input('SSL_Var: ')

And use the argument here:

c = Controller(controllerIP, userName, password, "8443", "v4", "default", sslCert)
clients = c.get_clients()
list = {}

I'm getting the error:

Traceback (most recent call last):
  File "/home/pi/client-mapping.py", line 58, in <module>
    c = Controller(controllerIP, userName, password, "8443", "v4", "default", sslCert)
  File "/usr/local/lib/python2.7/dist-packages/pyunifi/controller.py", line 113, in __init__
    self._login()
  File "/usr/local/lib/python2.7/dist-packages/pyunifi/controller.py", line 161, in _login
    r = self.session.post(login_url, json=params)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 416, in send
    self.cert_verify(conn, request.url, verify, cert)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 228, in cert_verify
    "invalid path: {}".format(cert_loc))
IOError: Could not find a suitable TLS CA certificate bundle, invalid path: False

So it seems it sees "False", but it's not seeing it as an input for "ssl_verify"

Any ideas? As you can tell, I'm still learning.

Thanks, Shane.

finish06 commented 4 years ago

@scrytch - What are you passing in for the certificate route? Is it a self-signed cert?

shanelord01 commented 4 years ago

@scrytch - What are you passing in for the certificate route? Is it a self-signed cert?

At the moment I'm just testing "True" or "False" statements, but would need to support a path too... at the moment the script isn't liking default = "False"

finish06 commented 3 years ago

Upon reviewing today, I recognized the code snipppet is sending a string, i.e. "False", instead of a boolean. Python would recognize the string 'False' as a True boolean. Closing ticket.