Retry Amazon requests after ReadTimeout exception.

This commit is contained in:
Oleg Plakhotniuk 2015-02-09 00:19:26 -06:00 committed by Romain Bignon
commit 365d7cfd4e

View file

@ -23,6 +23,7 @@ from weboob.browser.exceptions import ServerError, HTTPNotFound
from weboob.capabilities.base import Currency from weboob.capabilities.base import Currency
from weboob.capabilities.shop import OrderNotFound from weboob.capabilities.shop import OrderNotFound
from weboob.exceptions import BrowserIncorrectPassword from weboob.exceptions import BrowserIncorrectPassword
from requests.exceptions import ReadTimeout
from .pages import HomePage, LoginPage, AmazonPage, HistoryPage, \ from .pages import HomePage, LoginPage, AmazonPage, HistoryPage, \
OrderOldPage, OrderNewPage OrderOldPage, OrderNewPage
@ -33,6 +34,7 @@ __all__ = ['Amazon']
class Amazon(LoginBrowser): class Amazon(LoginBrowser):
BASEURL = 'https://www.amazon.com' BASEURL = 'https://www.amazon.com'
MAX_RETRIES = 10
home = URL(r'http://www\.amazon\.com/$', HomePage) home = URL(r'http://www\.amazon\.com/$', HomePage)
login = URL(r'/ap/signin/.*$', LoginPage) login = URL(r'/ap/signin/.*$', LoginPage)
history = URL(r'/gp/css/order-history.*$', HistoryPage) history = URL(r'/gp/css/order-history.*$', HistoryPage)
@ -106,6 +108,6 @@ class Amazon(LoginBrowser):
for i in xrange(self.MAX_RETRIES): for i in xrange(self.MAX_RETRIES):
try: try:
return super(Amazon, self).location(*args, **kwargs) return super(Amazon, self).location(*args, **kwargs)
except ServerError as e: except (ServerError, ReadTimeout) as e:
pass pass
raise e raise e