From 598eeaf52ee39bc2ec7855a65e1b65806355ce14 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 2 Dec 2019 23:47:50 -0600 Subject: [PATCH] Try new login success detection method --- auth.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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() -- 2.30.2