Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib.error: Error -5 while decompressing data: incomplete or truncated stream #7181

Open
remitamine opened this issue Oct 15, 2015 · 2 comments
Open

Comments

@remitamine
Copy link
Collaborator

@remitamine remitamine commented Oct 15, 2015

youtube-dl -v http://www.skysports.com/watch/video/10018211/rodgers-sacked-by-liverpool
[debug] System config: []
[debug] User config: ['--external-downloader', 'aria2c', '--external-downloader-args', '-x 16', '-f', '[height<=?720]', '--sub-lang', 'ar,arME,en', '--write-sub', '--no-check-certificate']
[debug] Command-line args: ['-v', 'http://www.skysports.com/watch/video/10018211/rodgers-sacked-by-liverpool']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2015.09.28
[debug] Python version 3.5.0 - Linux-4.2.3-1-ARCH-x86_64-with-arch
[debug] exe versions: ffmpeg 2.8.1, ffprobe 2.8.1, rtmpdump 2.4
[debug] Proxy map: {}
[generic] rodgers-sacked-by-liverpool: Requesting header
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/youtube_dl/utils.py", line 674, in deflate
    return zlib.decompress(data, -zlib.MAX_WBITS)
zlib.error: Error -5 while decompressing data: incomplete or truncated stream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/youtube-dl", line 9, in <module>
    load_entry_point('youtube-dl==2015.9.28', 'console_scripts', 'youtube-dl')()
  File "/usr/lib/python3.5/site-packages/youtube_dl/__init__.py", line 410, in main
    _real_main(argv)
  File "/usr/lib/python3.5/site-packages/youtube_dl/__init__.py", line 400, in _real_main
    retcode = ydl.download(all_urls)
  File "/usr/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1658, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/usr/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 660, in extract_info
    ie_result = ie.extract(url)
  File "/usr/lib/python3.5/site-packages/youtube_dl/extractor/common.py", line 288, in extract
    return self._real_extract(url)
  File "/usr/lib/python3.5/site-packages/youtube_dl/extractor/generic.py", line 1162, in _real_extract
    fatal=False)
  File "/usr/lib/python3.5/site-packages/youtube_dl/extractor/common.py", line 327, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "/usr/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1865, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 471, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/site-packages/youtube_dl/utils.py", line 748, in http_response
    gz = io.BytesIO(self.deflate(resp.read()))
  File "/usr/lib/python3.5/site-packages/youtube_dl/utils.py", line 676, in deflate
    return zlib.decompress(data)
zlib.error: Error -5 while decompressing data: incomplete or truncated stream
@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Oct 15, 2015

(For reference, this uses the url posted in #7066)

This only happens for HEAD requests because it returns no data, therefore zlib can't decompress it. This simple patch "fixes" it:

diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 7dbe256..dee3b00 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -670,6 +670,9 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler):

     @staticmethod
     def deflate(data):
+        # HEAD requests produce no data, which is not a valid compressed file
+        if not data:
+            return data
         try:
             return zlib.decompress(data, -zlib.MAX_WBITS)
         except zlib.error:

Although it could be better to handle it in YoutubeDLHandler.http_response.

@nielsangho
Copy link

@nielsangho nielsangho commented Jan 5, 2016

How do I apply this "fix"? @jaimeMF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.