Try new login success detection method
authorJakob <jakob@jcornell.net>
Tue, 3 Dec 2019 05:47:50 +0000 (23:47 -0600)
committerJakob <jakob@jcornell.net>
Tue, 3 Dec 2019 05:47:50 +0000 (23:47 -0600)
auth.py

diff --git a/auth.py b/auth.py
index e215d6fe12d2d1c63e14fa59db0a55156c629b06..ee66eb65638a3c3d1b33d1cd6817ef9faa53bfad 100644 (file)
--- 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()