From 6ee2aa0444e2d0a8ebfbddac4946d14b4ac94d39 Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Mon, 25 Nov 2019 11:07:23 +0100 Subject: [PATCH] [bp] Add retry when failing to go to market page Sometimes when going to the market space, the website returns an error 404 or 403. This is usually fixed the next time. The market_login.go() request is skipped if we already landed on the market home page after the first location. --- modules/bp/browser.py | 22 +++++++++++++++++++--- modules/bp/pages/accountlist.py | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/modules/bp/browser.py b/modules/bp/browser.py index ea0f7738a2..e4b98ea04b 100644 --- a/modules/bp/browser.py +++ b/modules/bp/browser.py @@ -22,6 +22,8 @@ import os from datetime import datetime, timedelta +from requests.exceptions import HTTPError + from weboob.browser import LoginBrowser, URL, need_login from weboob.browser.browsers import StatesMixin from weboob.browser.exceptions import ServerError @@ -43,7 +45,9 @@ LifeInsuranceInvest, LifeInsuranceHistory, LifeInsuranceHistoryInv, RetirementHistory, SavingAccountSummary, CachemireCatalogPage, ) -from .pages.accountlist import MarketLoginPage, UselessPage, ProfilePage, MarketCheckPage +from .pages.accountlist import ( + MarketLoginPage, UselessPage, ProfilePage, MarketCheckPage, MarketHomePage, +) from .pages.pro import RedirectPage, ProAccountsList, ProAccountHistory, DownloadRib, RibPage from .pages.mandate import MandateAccountsList, PreMandate, PreMandateBis, MandateLife, MandateMarket from .linebourse_browser import LinebourseBrowser @@ -105,6 +109,7 @@ class BPBrowser(LoginBrowser, StatesMixin): r'/voscomptes/canalXHTML/assurance/vie/detailMouvementHermesBompard-assuranceVie.ea\?idMouvement=(\w+)', LifeInsuranceHistoryInv) lifeinsurance_cachemire_catalog = URL(r'https://www.labanquepostale.fr/particuliers/bel_particuliers/assurance/accueil_cachemire.html', CachemireCatalogPage) + market_home = URL(r'https://labanquepostale.offrebourse.com/fr/\d+/?', MarketHomePage) market_login = URL(r'/voscomptes/canalXHTML/bourse/aiguillage/oicFormAutoPost.jsp', MarketLoginPage) market_check = URL(r'/voscomptes/canalXHTML/bourse/aiguillage/lancerBourseEnLigne-connexionBourseEnLigne.ea', MarketCheckPage) useless = URL(r'https://labanquepostale.offrebourse.com/ReroutageSJR', UselessPage) @@ -387,8 +392,19 @@ def get_history(self, account): @need_login def go_linebourse(self, account): - self.location(account.url) - self.market_login.go() + # Sometimes the redirection done from MarketLoginPage + # (to https://labanquepostale.offrebourse.com/ReroutageSJR) + # throws an error 404 or 403 + location = retry(HTTPError, delay=5)(self.location) + location(account.url) + + # TODO Might be deprecated, check the logs after some time to + # check if this is still used. + if not self.market_home.is_here(): + self.logger.debug('Landed in unexpected market page, doing self.market_login.go()') + go = retry(HTTPError, delay=5)(self.market_login.go) + go() + self.linebourse.session.cookies.update(self.session.cookies) self.par_accounts_checking.go() diff --git a/modules/bp/pages/accountlist.py b/modules/bp/pages/accountlist.py index d142eca3bc..785838ca79 100644 --- a/modules/bp/pages/accountlist.py +++ b/modules/bp/pages/accountlist.py @@ -424,6 +424,10 @@ def get_iban(self): return None +class MarketHomePage(LoggedPage, HTMLPage): + pass + + class MarketLoginPage(LoggedPage, PartialHTMLPage): def on_load(self): self.get_form(id='autoSubmit').submit() -- GitLab