From 219bcc3864cc543bdd90b9cce988b8d01dd9b0d7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 25 Jul 2019 10:46:06 +0530 Subject: [PATCH] py3 compat for gaierror retry --- src/calibre/web/fetch/simple.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/web/fetch/simple.py b/src/calibre/web/fetch/simple.py index b5b098d3c3..e0b4fefc5c 100644 --- a/src/calibre/web/fetch/simple.py +++ b/src/calibre/web/fetch/simple.py @@ -277,9 +277,13 @@ class RecursiveFetcher(object): except URLError as err: if hasattr(err, 'code') and err.code in responses: raise FetchError(responses[err.code]) - if getattr(err, 'reason', [0])[0] == 104 or \ - getattr(getattr(err, 'args', [None])[0], 'errno', None) in (-2, - -3): # Connection reset by peer or Name or service not known + is_temp = False + reason = getattr(err, 'reason', None) + if isinstance(reason, socket.gaierror): + # see man gai_strerror() for details + if getattr(reason, 'errno', None) in (socket.EAI_AGAIN, socket.EAI_NONAME): + is_temp = True + if is_temp: # Connection reset by peer or Name or service not known self.log.debug('Temporary error, retrying in 1 second') time.sleep(1) with closing(open_func(url, timeout=self.timeout)) as f: