def get_content_aware():
retry = urllib3.util.Retry(total=MAX_RETRIES,
connect=MAX_RETRIES,
read=MAX_RETRIES,
backoff_factor=BACKOFF_FACTOR)
def attempt(url, retry=retry):
try:
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
session.mount(RETRY_PREFIX, adapter)
req = requests.Request('GET', url).prepare()
r = session.send(req, timeout=TIMEOUT)
r.raise_for_status()
j = r.json()
# DEMO ONLY. TypeError is too wide to handle here
except (ConnectionError, TypeError) as e:
retry = retry.increment(req.method, url, error=e)
retry.sleep()
logging.warning("Retrying (%r) after connection broken by '%r': '%s'", retry, e, url)
return attempt(url, retry=retry)
return j
return attempt(URL)
评论列表
文章目录