def require_phone_number(self, html, session): logger.info( 'Auth requires phone number. You do login from unusual place') # Raises VkPageWarningsError in case of warnings # NOTE: we check only 'security_check' case on warnings for now # in future it might be propagated to other cases as well check_html_warnings(html=html) # Determine form action url action_url = parse_form_action_url(html) # Get masked phone from html to make things more clear phone_prefix, phone_suffix = parse_masked_phone_number(html) if self._phone_number: code = self._phone_number[len(phone_prefix):-len(phone_suffix)] else: prompt = 'Enter missing digits of your phone number (%s****%s): '\ % (phone_prefix, phone_suffix) code = raw_input(prompt) params = parse_url_query_params(action_url, fragment=False) auth_data = { 'code': code, 'act': 'security_check', 'hash': params['hash']} response = session.post( url=self.LOGIN_URL + action_url, data=auth_data) logger.debug('require_phone_number resp: %s', response.text)
def require_phone_number(self, html, session): logger.info( 'Auth requires phone number. You do login from unusual place') # Raises VkPageWarningsError in case of warnings # NOTE: we check only 'security_check' case on warnings for now # in future it might be propagated to other cases as well check_html_warnings(html=html) # Determine form action url action_url = parse_form_action_url(html) # Get masked phone from html to make things more clear phone_prefix, phone_suffix = parse_masked_phone_number(html) if self._phone_number: code = self._phone_number[len(phone_prefix):-len(phone_suffix)] else: prompt = 'Enter missing digits of your phone number (%s****%s): '\ % (phone_prefix, phone_suffix) code = raw_input(prompt) params = parse_url_query_params(action_url, fragment=False) auth_data = { 'code': code, 'act': 'security_check', 'hash': params['hash'] } response = session.post(url=self.LOGIN_URL + action_url, data=auth_data) logger.debug('require_phone_number resp: %s', response.text)
def test_check_html_warnings(self): html = get_fixture('require_phone_num_resp.html') html_with_warn = get_fixture('require_phone_num_warn_resp.html') # No warnings - expect True self.assertTrue(utils.check_html_warnings(html)) with self.assertRaises(VkPageWarningsError) as err: result = utils.check_html_warnings(html_with_warn) self.assertIsNone(result) self.assertIn('Incorrect numbers.', str(err))