Commit ac5161f0 authored by Benjamin Tampigny's avatar Benjamin Tampigny Committed by Vincent A

|cmso] don't crash the second time market history is requested

Since the error is now handled properly, the try except is not useful
anymore, I deleted it
parent 85e6031f
......@@ -330,11 +330,15 @@ class CmsoParBrowser(TwoFactorBrowser):
self.accounts_list.append(a)
return self.accounts_list
def _go_market_history(self):
content = self.market.go(json={'place': 'SITUATION_PORTEFEUILLE'}).text
self.location(json.loads(content)['urlSSO'])
return self.market.go(website=self.website, action='historiquePortefeuille')
def _go_market_history(self, action):
# the website won't let us go on market page if we don't do this call before (it raises a 403)
self.redirect_insurance.go()
try:
url_before_market_history = json.loads(self.market.go(json={'place': 'SITUATION_PORTEFEUILLE'}).text)['urlSSO']
except KeyError:
raise AssertionError('unable to get url to reach to be able to go on market page')
self.location(url_before_market_history)
return self.market.go(website=self.website, action=action)
@retry((ClientError, ServerError))
@need_login
......@@ -355,7 +359,7 @@ class CmsoParBrowser(TwoFactorBrowser):
yield tr
return
elif account.type in (Account.TYPE_PEA, Account.TYPE_MARKET):
self._go_market_history()
self._go_market_history('historiquePortefeuille')
if not self.page.go_account(account.label, account._owner):
return
......@@ -417,10 +421,12 @@ class CmsoParBrowser(TwoFactorBrowser):
return []
comings = []
if not hasattr(account, '_index'):
# No _index, we can't get coming
return []
elif account.type in (Account.TYPE_PEA, Account.TYPE_MARKET):
# will prevent a further 403
self.redirect_insurance.go()
self.history.go(json={"index": account._index}, page="pendingListOperations")
# There is no ids for comings, so no check for duplicates
for key in self.page.get_keys():
......@@ -450,10 +456,7 @@ class CmsoParBrowser(TwoFactorBrowser):
return []
return self.location(url).page.iter_investment()
elif account.type in (Account.TYPE_MARKET, Account.TYPE_PEA):
data = {"place": "SITUATION_PORTEFEUILLE"}
response = self.market.go(json=data)
self.location(json.loads(response.text)['urlSSO'])
self.market.go(website=self.website, action="situationPortefeuille")
self._go_market_history('situationPortefeuille')
if self.page.go_account(account.label, account._owner):
return self.page.iter_investment()
return []
......@@ -465,10 +468,7 @@ class CmsoParBrowser(TwoFactorBrowser):
if account.type not in (Account.TYPE_MARKET, Account.TYPE_PEA):
return
data = {"place": "SITUATION_PORTEFEUILLE"}
response = self.market.go(json=data)
self.location(json.loads(response.text)['urlSSO'])
self.market.go(website=self.website, action="carnetOrdre")
self._go_market_history('carnetOrdre')
if self.page.go_account(account.label, account._owner):
orders_list_url = self.url
error_message = self.page.get_error_message()
......
......@@ -38,7 +38,7 @@ from weboob.browser.filters.standard import (
)
from weboob.browser.filters.json import Dict
from weboob.browser.filters.html import Attr, Link, TableCell, AbsoluteLink
from weboob.browser.exceptions import ServerError, ClientError
from weboob.browser.exceptions import ServerError
from weboob.capabilities.bank import Account, Loan, AccountOwnership
from weboob.capabilities.wealth import Investment, MarketOrder, MarketOrderDirection, MarketOrderType
from weboob.capabilities.contact import Advisor
......@@ -289,16 +289,7 @@ class AccountsPage(LoggedPage, JsonPage):
def get_market_number(self):
label = Field('label')(self)
# 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
page = self.page.browser._go_market_history('historiquePortefeuille')
return page.get_account_id(label, Field('_owner')(self))
def get_lifenumber(self):
......
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