I tried to use pyunifi against a Cloud Key Gen2 plus, and I found a login issue to it.
I tried to use version="unifiOS" and then I got this error back:
raise APIError("Login failed - status code: %i" % r.status_code)
APIError: Login failed - status code: 401
I used F12 to login to the cloud key, and checked which URI it posted the login call to.
It is supposted to be towards: https://IP/api/auth/login.
In the script, the self.url is:
self.url = 'https://' + host + '/proxy/network/'
and the login function is using self.url like this:
login_url = self.url + 'api/login'
Which means it gets /proxy/network/ before api/login.
So I changed the init from:
if version == "unifiOS":
self.host = host
self.username = username
self.password = password
self.site_id = site_id
self.ssl_verify = ssl_verify
self.url = 'https://' + host + '/proxy/network/'
to:
if version == "unifiOS":
self.host = host
self.username = username
self.password = password
self.site_id = site_id
self.ssl_verify = ssl_verify
self.url = 'https://' + host + '/proxy/network/'
self.urllogin= 'https://' + host + '/'
self.version=version
And the login function I changed from this:
def _login(self):
log.debug('login() as %s', self.username)
# XXX Why doesn't passing in the dict work?
params = {'username': self.username, 'password': self.password}
login_url = self.url + 'api/login'
To:
def _login(self):
log.debug('login() as %s', self.username)
# XXX Why doesn't passing in the dict work?
params = {'username': self.username, 'password': self.password}
if self.version=="v5":
login_url = self.url + 'api/login'
elif self.version=="unifiOS":
login_url = self.urllogin + 'api/auth/login'
And then I could login to the Cloud key and pull everything I needed.
Just wanted to inform you about this issue, awesome job with the library!
I tried to use pyunifi against a Cloud Key Gen2 plus, and I found a login issue to it.
I tried to use version="unifiOS" and then I got this error back:
raise APIError("Login failed - status code: %i" % r.status_code)
APIError: Login failed - status code: 401
I used F12 to login to the cloud key, and checked which URI it posted the login call to.
It is supposted to be towards: https://IP/api/auth/login.
In the script, the self.url is:
self.url = 'https://' + host + '/proxy/network/'
and the login function is using self.url like this:
login_url = self.url + 'api/login'
Which means it gets /proxy/network/ before api/login.
So I changed the init from:
if version == "unifiOS":
self.host = host
self.username = username
self.password = password
self.site_id = site_id
self.ssl_verify = ssl_verify
self.url = 'https://' + host + '/proxy/network/'
to:
if version == "unifiOS":
self.host = host
self.username = username
self.password = password
self.site_id = site_id
self.ssl_verify = ssl_verify
self.url = 'https://' + host + '/proxy/network/'
self.urllogin= 'https://' + host + '/'
self.version=version
And the login function I changed from this:
def _login(self):
log.debug('login() as %s', self.username)
To:
def _login(self):
log.debug('login() as %s', self.username)
And then I could login to the Cloud key and pull everything I needed.
Just wanted to inform you about this issue, awesome job with the library!