From 9b2ada5dd03b1f8294497912320413c6735a9f2d Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 10 Feb 2019 16:06:58 +0200 Subject: [PATCH] Retry on any exception Also seen these when testing: WSError: User not found MalformedResponseError: Malformed response from Last.fm. Underlying error: mismatched tag: line 6, column 2 NetworkError: NetworkError: [Errno 8] nodename nor servname provided, or not known --- pylast/__init__.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 48f918a..dc71cf5 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -2777,27 +2777,17 @@ def _collect_nodes(limit, sender, method_name, cacheable, params=None): while not end_of_pages and (not limit or (limit and len(nodes) < limit)): params["page"] = str(page) - tries = 0 + tries = 1 while True: - tries += 1 try: doc = sender._request(method_name, cacheable, params) break # success - except MalformedResponseError as e: - if tries < 3: - time.sleep(1) # wait and try again - else: - raise e - except WSError as e: - if tries < 3 and int(e.get_id()) in [ - # "Please try again" statuses - STATUS_OPERATION_FAILED, - STATUS_OFFLINE, - STATUS_TEMPORARILY_UNAVAILABLE, - ]: - time.sleep(1) # wait and try again - else: + except Exception as e: + if tries >= 3: raise e + # Wait and try again + time.sleep(1) + tries += 1 doc = cleanup_nodes(doc)