From f6f513fbea27139da65ba5f0047869ceeded9ed8 Mon Sep 17 00:00:00 2001 From: bato3 Date: Tue, 31 Jul 2018 13:04:58 +0200 Subject: [PATCH 1/2] Close socket after downloading page. On windows, when I make many requests it gives me error: **Python urllib2. URLError: ** according to: https://stackoverflow.com/questions/4526933/python-urllib2-urlerror-urlopen-error-errno-10048-only-one-usage-of-each-so --- youtube_dl/extractor/common.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index b8bbaf81a..b0892018c 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -769,6 +769,7 @@ class InfoExtractor(object): return res else: content, _ = res + _.close() return content def _download_xml_handle( @@ -807,7 +808,12 @@ class InfoExtractor(object): transform_source=transform_source, fatal=fatal, encoding=encoding, data=data, headers=headers, query=query, expected_status=expected_status) - return res if res is False else res[0] + if res is False: + return res + else: + content, _ = res + _.close() + return content def _parse_xml(self, xml_string, video_id, transform_source=None, fatal=True): if transform_source: @@ -857,7 +863,12 @@ class InfoExtractor(object): transform_source=transform_source, fatal=fatal, encoding=encoding, data=data, headers=headers, query=query, expected_status=expected_status) - return res if res is False else res[0] + if res is False: + return res + else: + content, _ = res + _.close() + return content def _parse_json(self, json_string, video_id, transform_source=None, fatal=True): if transform_source: From 8c8a1c095640ce2b0cf406ae3d8a429f511e2e24 Mon Sep 17 00:00:00 2001 From: bato3 Date: Tue, 31 Jul 2018 18:28:40 +0200 Subject: [PATCH 2/2] `_` -> `urlh` --- youtube_dl/extractor/common.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index b0892018c..c32ce8e04 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -768,8 +768,8 @@ class InfoExtractor(object): if res is False: return res else: - content, _ = res - _.close() + content, urlh = res + urlh.close() return content def _download_xml_handle( @@ -811,8 +811,8 @@ class InfoExtractor(object): if res is False: return res else: - content, _ = res - _.close() + content, urlh = res + urlh.close() return content def _parse_xml(self, xml_string, video_id, transform_source=None, fatal=True): @@ -866,8 +866,8 @@ class InfoExtractor(object): if res is False: return res else: - content, _ = res - _.close() + content, urlh = res + urlh.close() return content def _parse_json(self, json_string, video_id, transform_source=None, fatal=True):