def fetch_json(self, url):
"""Fetch remote json"""
timeout = 1
while True:
try:
logging.debug('Opening %s.', url)
response = urllib2.urlopen(url)
break
except urllib2.HTTPError as err:
if timeout <= MAX_TIMEOUT:
logging.warn('Error opening %s, error code %d, reason is %s.', url, err.code, err.reason)
logging.warn('Waiting for %ds before retrying.', timeout)
time.sleep(timeout)
timeout *= 2
else:
logging.error('Error opening %s, error code %d, reason is %s.', url, err.code, err.reason)
raise err
data = json.load(response)
return data
评论列表
文章目录