class woob.browser.retry.RetryLoginBrowser(*args, **kwargs)

Bases: woob.browser.browsers.LoginBrowser

Browser that can retry methods if the site logs out the session.

Some sites can terminate a session anytime, redirecting to a login page. To avoid having to handle it in the middle of every method, one can simply let logouts raise a woob.browser.exceptions.LoggedOut exception that is handled with a retry, thanks to the @retry_on_logout decorator.

The woob.browser.pages.LoginPage will raise LoggedOut if the browser is not currently logging in. To detect this situation, the do_login method MUST be decorated with @login_method.

Accept any arguments, necessary for AbstractBrowser __new__ override.

AbstractBrowser, in its overridden __new__, removes itself from class hierarchy so its __new__ is called only once. In python 3, default (object) __new__ is then used for next instantiations but it’s a slot/”fixed” version supporting only one argument (type to instanciate).


Decorate a method to indicate the browser is logging in.

When the decorated method is called, pages like woob.browser.pages.LoginPage will not raise LoggedOut, since it is expected for the browser not to be logged yet.

woob.browser.retry.retry_on_logout(exc_check=<class 'woob.browser.exceptions.LoggedOut'>, tries=4)

Decorate a function to retry several times in case of exception.

The decorated function is called at max 4 times. It is retried only when it raises an exception of the type woob.browser.exceptions.LoggedOut. If the function call succeeds and returns an iterator, a wrapper to the iterator is returned. If iterating on the result raises a LoggedOut, the iterator is recreated by re-calling the function, but the values already yielded will not be re-yielded. For consistency, the function MUST always return values in the same order.

Adding this decorator to a method which can be called from another decorated method should be avoided, since nested calls will greatly increase the number of retries.