Added mechanism retry for url fetch
This commit is contained in:
parent
34de0cb7e5
commit
cd31a1a8bf
|
@ -112,13 +112,16 @@ class RSSVoDServer(webapp2.RequestHandler):
|
||||||
'Client-ID': TWITCH_CLIENT_ID
|
'Client-ID': TWITCH_CLIENT_ID
|
||||||
}
|
}
|
||||||
request = urllib2.Request(url, headers=headers)
|
request = urllib2.Request(url, headers=headers)
|
||||||
try:
|
retries = 0
|
||||||
result = urllib2.urlopen(request)
|
while retries < 3:
|
||||||
logging.debug('Fetch from twitch for %s with code %s' % (id, result.getcode()))
|
try:
|
||||||
return result.read()
|
result = urllib2.urlopen(request, timeout=3)
|
||||||
except urllib2.URLError as e:
|
logging.debug('Fetch from twitch for %s with code %s' % (id, result.getcode()))
|
||||||
logging.warning("Fetch exception caught: %s" % e)
|
return result.read()
|
||||||
return ''
|
except BaseException as e:
|
||||||
|
logging.warning("Fetch exception caught: %s" % e)
|
||||||
|
retries += 1
|
||||||
|
return ''
|
||||||
|
|
||||||
def extract_userid(self, user_info):
|
def extract_userid(self, user_info):
|
||||||
userlist = user_info.get('users')
|
userlist = user_info.get('users')
|
||||||
|
|
Loading…
Reference in New Issue