From a5bc85ad02bab9b15409b665b2f7661947ce1a6b Mon Sep 17 00:00:00 2001 From: Vincent Ardisson Date: Thu, 15 Nov 2018 19:24:21 +0100 Subject: [PATCH] [boursorama] retry when par accounts seem unavailable with unexpected error --- modules/boursorama/browser.py | 20 ++++++++++++++++++-- modules/boursorama/pages.py | 9 +++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/modules/boursorama/browser.py b/modules/boursorama/browser.py index ddc7da2b1d..a850127f3d 100644 --- a/modules/boursorama/browser.py +++ b/modules/boursorama/browser.py @@ -26,7 +26,7 @@ from weboob.browser.retry import login_method, retry_on_logout, RetryLoginBrowser from weboob.browser.browsers import need_login, StatesMixin from weboob.browser.url import URL -from weboob.exceptions import BrowserIncorrectPassword, BrowserHTTPNotFound +from weboob.exceptions import BrowserIncorrectPassword, BrowserHTTPNotFound, BrowserUnavailable from weboob.browser.exceptions import LoggedOut, ClientError from weboob.capabilities.bank import ( Account, AccountNotFound, TransferError, TransferInvalidAmount, @@ -45,6 +45,7 @@ CardsNumberPage, CalendarPage, HomePage, PEPPage, TransferAccounts, TransferRecipients, TransferCharac, TransferConfirm, TransferSent, AddRecipientPage, StatusPage, CardHistoryPage, CardCalendarPage, CurrencyListPage, CurrencyConvertPage, + AccountsErrorPage, ) @@ -69,6 +70,7 @@ class BoursoramaBrowser(RetryLoginBrowser, StatesMixin): '/infos-profil', ErrorPage) login = URL('/connexion/', LoginPage) accounts = URL('/dashboard/comptes\?_hinclude=300000', AccountsPage) + accounts_error = URL('/dashboard/comptes\?_hinclude=300000', AccountsErrorPage) pro_accounts = URL(r'/dashboard/comptes-professionnels\?_hinclude=1', AccountsPage) acc_tit = URL('/comptes/titulaire/(?P.*)\?_hinclude=1', AccbisPage) acc_rep = URL('/comptes/representative/(?P.*)\?_hinclude=1', AccbisPage) @@ -189,13 +191,24 @@ def go_cards_number(self, link): @need_login def get_accounts_list(self): self.status.go() + + exc = None for x in range(3): if self.accounts_list is not None: break self.accounts_list = [] self.loans_list = [] self.accounts_list.extend(self.pro_accounts.go().iter_accounts()) - self.accounts_list.extend(self.accounts.go().iter_accounts()) + try: + self.accounts.go() + except BrowserUnavailable as e: + self.logger.warning('par accounts seem unavailable, retrying') + exc = e + self.accounts_list = None + continue + else: + self.accounts_list.extend(self.page.iter_accounts()) + exc = None # discard all unvalid card accounts (if opposed or not yet activated) valid_card_url = [] @@ -234,6 +247,9 @@ def get_accounts_list(self): checking, = [account for account in self.accounts_list if account.type == Account.TYPE_CHECKING and account.url in card.url] card.parent = checking + if exc: + raise exc + return self.accounts_list def get_account(self, id): diff --git a/modules/boursorama/pages.py b/modules/boursorama/pages.py index c6141ba64a..15fe9cf194 100644 --- a/modules/boursorama/pages.py +++ b/modules/boursorama/pages.py @@ -1105,3 +1105,12 @@ class CurrencyConvertPage(JsonPage): def get_rate(self): if not 'error' in self.doc: return round(self.doc['rate'], 4) + + +class AccountsErrorPage(LoggedPage, HTMLPage): + def is_here(self): + # some braindead error seems to affect many accounts until we retry + return '[E10008]' in CleanText('//div')(self.doc) + + def on_load(self): + raise BrowserUnavailable() -- GitLab