Commit 74cf825f authored by Stephane Sobucki's avatar Stephane Sobucki Committed by Vincent A

[hsbc] Handle more login errors

Handle more login error messages, updated XPath for errors in
LoginPage's `on_load()` method.

Additionaly, added login errors check in `end_login()` to avoid
FormNotFound exception due to a blocked account access.
parent 4f22e3e4
......@@ -32,7 +32,10 @@
from import sorted_transactions, keep_only_card_transactions
from import parse_qsl, urlparse
from import Value
from woob.exceptions import ActionNeeded, BrowserIncorrectPassword, BrowserUnavailable, BrowserQuestion
from woob.exceptions import (
BrowserIncorrectPassword, BrowserPasswordExpired, BrowserUnavailable,
BrowserUserBanned, BrowserQuestion,
from woob.browser import URL, need_login, TwoFactorBrowser
from woob.browser.exceptions import HTTPNotFound
from woob.capabilities.base import find_object
......@@ -170,6 +173,18 @@ def handle_otp(self):, otp)
def check_login_error(self):
error_msg =
if error_msg:
if 'Please click Reset Credentials' in error_msg or 'Please reset your HSBC Secure Key' in error_msg:
raise BrowserPasswordExpired(error_msg)
elif 'Please retry in 30 minutes' in error_msg:
raise BrowserUserBanned(error_msg)
raise AssertionError('Unhandled error at login: %s' % error_msg)
def init_login(self):
......@@ -192,12 +207,7 @@ def init_login(self):
if no_secure_key_link:
error =
if error and 'Please click Reset Credentials' in error:
raise ActionNeeded(error)
elif error:
raise AssertionError('Unhandled error at login: %s' % error)
raise BrowserQuestion(
......@@ -211,6 +221,7 @@ def init_login(self):
def end_login(self):
for _ in range(3):
if self.login.is_here():
# This wonderful website has 2 baseurl with only one difference: the 's' at the end of 'client'
......@@ -559,17 +559,18 @@ def logged(self):
return False
def on_load(self):
for message in self.doc.xpath('//div[has-class("csPanelErrors")]'):
for message in self.doc.xpath('//div[@class="mainBloc"]/*[@class="error"]'): # Sometimes <p>, sometimes <div>
error_msg = CleanText('.')(message)
if any(
msg in error_msg
for msg in [
'Please enter valid credentials for memorable answer and password.',
'Please enter a valid Username.',
'mot de passe invalide',
'Log on error', # wrong otp
error_at_login_regex = re.compile(
'Please enter valid credentials for memorable answer and password.'
+ '|Please enter a valid Username.'
+ '|mot de passe invalide'
+ '|Log on error' # wrong otp
raise BrowserIncorrectPassword(error_msg)
raise BrowserUnavailable(error_msg)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment