From ef3bd4f09a0955aefd4d19bf8212003e07769cf0 Mon Sep 17 00:00:00 2001 From: Benjamin Tampigny Date: Wed, 1 Jul 2020 12:14:30 +0200 Subject: [PATCH] [cmso] don't crash a full iter_accounts for a market_number For some reasons, trying to go to market history during an iter_savings can cause a ClientError. If not handled, this exception will make the browser try to relogin and start over the iter_accounts but the session is actualy not lost. In this case, we juste handle it when retrieving the market order and in the worst case we won't have this information --- modules/cmso/par/pages.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/cmso/par/pages.py b/modules/cmso/par/pages.py index 6fb0f5d28c..a9113742a0 100644 --- a/modules/cmso/par/pages.py +++ b/modules/cmso/par/pages.py @@ -38,7 +38,7 @@ ) from weboob.browser.filters.json import Dict from weboob.browser.filters.html import Attr, Link, TableCell, AbsoluteLink -from weboob.browser.exceptions import ServerError +from weboob.browser.exceptions import ServerError, ClientError from weboob.capabilities.bank import Account, Loan, AccountOwnership from weboob.capabilities.wealth import Investment, MarketOrder, MarketOrderDirection, MarketOrderType from weboob.capabilities.contact import Advisor @@ -289,7 +289,16 @@ def obj_ownership(self): def get_market_number(self): label = Field('label')(self) - page = self.page.browser._go_market_history() + # sometimes this call raises a ClientError. it does not really disconnect the browser + # in order to prevent a new login attempt from the browser and a reset of the iter_accounts + # we handle the exception here + try: + page = self.page.browser._go_market_history() + except ClientError as e: + if e.response.status_code == 403: + self.logger.warning("unable to retrieve market number for account with label %s", label) + return NotAvailable + raise return page.get_account_id(label, Field('_owner')(self)) def get_lifenumber(self): -- GitLab