- # post some token to SSO to get login page
- with self.opener.open(urllib.request.Request(curr_url, data = body.encode('ascii'), method = method)) as resp:
- soup = bs4.BeautifulSoup(resp, 'lxml')
- form = soup.find('form')
- curr_url = util.resolve(form['action'], curr_url)
- method = form['method'].upper()
- (user, pass_) = get_credentials(self.config_path)
- data = {
- 'j_username': user,
- 'j_password': pass_,
- '_eventId_proceed': '',
- }
- body = urllib.parse.urlencode(data)
-
- # post login credentials
- with self.opener.open(urllib.request.Request(curr_url, data = body.encode('ascii'), method = method)) as resp:
- soup = bs4.BeautifulSoup(resp, 'lxml')
- form = soup.find('form')
- curr_url = util.resolve(form['action'], curr_url)
- method = form['method'].upper()
- params = {inp['name']: inp['value'] for inp in form.find_all('input', type = 'hidden')}
- body = urllib.parse.urlencode(params)
-
- # post token back to Blackboard
- with self.opener.open(urllib.request.Request(curr_url, data = body.encode('ascii'), method = method)) as resp:
- soup = bs4.BeautifulSoup(resp, 'lxml')
+ req = urllib.request.Request(
+ util.resolve(form['action'], url),
+ method = form['method'],
+ data = body,
+ )
+ with self.opener.open(req) as resp:
+ resp.read()