[extractor/common] Ensure response handle is not prematurely closed before it can...
[youtube-dl] / youtube_dl / extractor / common.py
index 8452125c8802b1398698c334084c85b673e80964..e5f8136fc1511d573978298393f5aba5d94d7af8 100644 (file)
@@ -606,6 +606,11 @@ class InfoExtractor(object):
         except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
             if isinstance(err, compat_urllib_error.HTTPError):
                 if self.__can_accept_status_code(err, expected_status):
+                    # Retain reference to error to prevent file object from
+                    # being closed before it can be read. Works around the
+                    # effects of <https://bugs.python.org/issue15002>
+                    # introduced in Python 3.4.1.
+                    err.fp._error = err
                     return err.fp
 
             if errnote is False: