Retry http timeout errors
This commit is contained in:
parent
5476352b53
commit
94b1617d7e
|
@ -44,12 +44,16 @@ class Response:
|
||||||
|
|
||||||
|
|
||||||
def open(url: str, params: Mapping = None) -> Response:
|
def open(url: str, params: Mapping = None) -> Response:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
if params is not None:
|
if params is not None:
|
||||||
url += "?" + urllib.parse.urlencode(params)
|
url += "?" + urllib.parse.urlencode(params)
|
||||||
request = Request(url)
|
request = Request(url)
|
||||||
request.add_header("User-Agent", HTTP_USER_AGENT)
|
request.add_header("User-Agent", HTTP_USER_AGENT)
|
||||||
http_response = urllib.request.urlopen(request, timeout=HTTP_TIMEOUT)
|
http_response = urllib.request.urlopen(request, timeout=HTTP_TIMEOUT)
|
||||||
return Response(http_response)
|
return Response(http_response)
|
||||||
|
except TimeoutError as e:
|
||||||
|
logger.exception("Timeout", exc_info=e)
|
||||||
|
|
||||||
|
|
||||||
def download_zip(url: str, dest: Path) -> None:
|
def download_zip(url: str, dest: Path) -> None:
|
||||||
|
|
Loading…
Reference in a new issue