mirror of
https://github.com/soimort/you-get.git
synced 2025-02-10 12:12:26 +03:00
Handle HTTPExcpetion and clean up urlopen_with_retry
This commit is contained in:
parent
58cd2a0de5
commit
c4519c0ef0
@ -12,6 +12,7 @@ import logging
|
|||||||
import argparse
|
import argparse
|
||||||
import ssl
|
import ssl
|
||||||
from http import cookiejar
|
from http import cookiejar
|
||||||
|
from http.client import HTTPException
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from urllib import request, parse, error
|
from urllib import request, parse, error
|
||||||
|
|
||||||
@ -407,19 +408,10 @@ def urlopen_with_retry(*args, **kwargs):
|
|||||||
return request.urlopen(*args, context=ctx, **kwargs)
|
return request.urlopen(*args, context=ctx, **kwargs)
|
||||||
else:
|
else:
|
||||||
return request.urlopen(*args, **kwargs)
|
return request.urlopen(*args, **kwargs)
|
||||||
except socket.timeout as e:
|
except (socket.timeout, error.HTTPError, error.URLError, HTTPException) as e:
|
||||||
logging.debug('request attempt %s timeout' % str(i + 1))
|
logging.debug('request attempt {} failed: {}'.format(i + 1, e))
|
||||||
if i + 1 == retry_time:
|
if i + 1 == retry_time:
|
||||||
raise e
|
raise e
|
||||||
# try to tackle youku CDN fails
|
|
||||||
except error.HTTPError as http_error:
|
|
||||||
logging.debug('HTTP Error with code{}'.format(http_error.code))
|
|
||||||
if i + 1 == retry_time:
|
|
||||||
raise http_error
|
|
||||||
except error.URLError as url_error:
|
|
||||||
logging.debug('URL Error: {}'.format(url_error))
|
|
||||||
if i + 1 == retry_time:
|
|
||||||
raise url_error
|
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user