Commit f4ca5a8c authored by Florian Duguet's avatar Florian Duguet Committed by Romain Bignon

[edf] fix download document

sometimes document is not found, and edf return an html page
retry one time if that occur and raise an exception the second time
to avoid to return an html page instead of pdf

Closes: 8906@zendesk
parent 75d096a8
......@@ -23,6 +23,7 @@ from time import time
from weboob.browser import LoginBrowser, URL, need_login
from weboob.browser.exceptions import ClientError
from weboob.exceptions import BrowserIncorrectPassword, NocaptchaQuestion
from weboob.tools.decorators import retry
from weboob.tools.json import json
from .pages import (
HomePage, AuthenticatePage, AuthorizePage, CheckAuthenticatePage, ProfilPage,
......@@ -30,6 +31,10 @@ from .pages import (
)
class BrokenPageError(Exception):
pass
class EdfBrowser(LoginBrowser):
BASEURL = 'https://particulier.edf.fr'
......@@ -111,6 +116,7 @@ class EdfBrowser(LoginBrowser):
return self.bills.go().iter_bills(subid=subscription.id)
@retry(BrokenPageError, tries=2, delay=4)
@need_login
def download_document(self, document):
token = self.get_csrf_token()
......@@ -127,9 +133,15 @@ class EdfBrowser(LoginBrowser):
'parNumber': document._par_number
})).get_bills_informations()
return self.bill_download.go(csrf_token=token, dn='FACTURE', pn=document._par_number,
di=document._doc_number, bn=bills_informations.get('bpNumber'),
an=bills_informations.get('numAcc')).content
self.bill_download.go(csrf_token=token, dn='FACTURE', pn=document._par_number,
di=document._doc_number, bn=bills_informations.get('bpNumber'),
an=bills_informations.get('numAcc'))
# sometimes we land to another page that tell us, this document doesn't exist, but just sometimes...
# make sure this page is the right one to avoid return a html page as document
if not self.bill_download.is_here():
raise BrokenPageError()
return self.page.content
@need_login
def get_profile(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