Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with login into a Cloud Key Gen2 plus #62

Open
Borgenstrand opened this issue Mar 13, 2021 · 6 comments
Open

Issues with login into a Cloud Key Gen2 plus #62

Borgenstrand opened this issue Mar 13, 2021 · 6 comments

Comments

@Borgenstrand
Copy link

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!

@holblin
Copy link

holblin commented Mar 24, 2021

@finish06 , I think this is fixed in the development branch and with UDMP-unifiOS version?
When, did you plan to make a new release? This is also seems to block custom-components/sensor.unifigateway#17 / custom-components/sensor.unifigateway#35 and probably more.

@geftactics
Copy link

Here to express my excitement for a new release from dev branch! :)

@finish06
Copy link
Owner

FYI: v2.21 has been uploaded to PyPi and is reported to have fixed these issues. Let me know what you find. Thanks.

@mgottholsen
Copy link

Tested it out today with a USG4 and a Cloud Key Gen 2, and unfortunately the 401 issue still exists. Is there a sample I can provide from my Unifi setup that will help?

@finish06
Copy link
Owner

finish06 commented Apr 20, 2021

@mgottholsen - I do not have a CloudKey. Can you confirm the URL that is being accessed when logging into the CloudKey? Also, please provide the software version on the CloudKey2.

@copart
Copy link

copart commented Aug 24, 2021

Just wanted to say that I can use pyunifi (2.21 version) with my CK+ when I set version to UDMP-unifiOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants