Skip to content

Commit

Permalink
Merge pull request calmh#43 from saroberts/master
Browse files Browse the repository at this point in the history
Fix login to v4 controller with python v3.  Generalize login procedure.
  • Loading branch information
calmh committed Jan 2, 2016
2 parents 20d2f8d + b42b7b9 commit 06a89e8
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions unifi/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,25 @@ def _construct_api_path(self, version):

def _login(self, version):
log.debug('login() as %s', self.username)

if(version == 'v4'):
params = "{'username':'" + self.username + "','password':'" + self.password + "'}"
self.opener.open(self.url + 'api/login', params).read()

params = {'username': self.username, 'password': self.password}
login_url = self.url

if version is 'v4':
login_url += 'api/login'
params = json.dumps(params)
else:
if PYTHON_VERSION == 2:
params = urllib.urlencode({'login': 'login',
'username': self.username, 'password': self.password})
elif PYTHON_VERSION == 3:
params = urllib.parse.urlencode({'login': 'login',
'username': self.username, 'password': self.password}).encode("UTF-8")
self.opener.open(self.url + 'login', params).read()
login_url += 'login'
params.update({'login': 'login'})
if PYTHON_VERSION is 2:
params = urllib.urlencode(params)
elif PYTHON_VERSION is 3:
params = urllib.parse.urlencode(params)

if PYTHON_VERSION is 3:
params = params.encode("UTF-8")

self.opener.open(login_url, params).read()

def _logout(self):
log.debug('logout()')
Expand Down

0 comments on commit 06a89e8

Please sign in to comment.