])
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()