From: Jakob Date: Tue, 3 Dec 2019 05:47:50 +0000 (-0600) Subject: Try new login success detection method X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=598eeaf52ee39bc2ec7855a65e1b65806355ce14;p=bb-sync-api.git Try new login success detection method --- diff --git a/auth.py b/auth.py index e215d6f..ee66eb6 100644 --- a/auth.py +++ b/auth.py @@ -300,22 +300,33 @@ class CookieAuthHandler(urllib.request.HTTPCookieProcessor): ]) body = urllib.parse.urlencode(params).encode('ascii') + opener = urllib.request.OpenerDirector() + handlers = [ + urllib.request.HTTPHandler(), + urllib.request.HTTPSHandler(), + urllib.request.HTTPErrorHandler, + self, + ] + for h in handlers: + opener.add_handler(h) req = urllib.request.Request( util.resolve(form['action'], url), method = form['method'], data = body, ) - with self.parent.open(req) as resp: + with opener.open(req) as resp: resp.read() - path = PurePosixPath(urllib.parse.urlparse(resp.url).path) - if path.match('*/webapps/login'): + if resp.status == 200: log('error', "Login failed. Are your credentials correct?") del self.storage_mgr['username'] del self.storage_mgr['password'] - else: + elif resp.status == 302: + # success self.storage_mgr['username'] = username self.storage_mgr['password'] = encode(password) + else: + raise AssertionError() self.cookiejar.save()