Skip to content

plugin.api.http_session: enforce_content_length #3768

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

Conversation

bastimeyer
Copy link
Member

Resolves #2365

This should resolve #2365, but I can't validate it myself with data of real HLS streams and don't want to spend time writing sophisticated tests for the entire upstream stack where this bug occurs.

See psf/requests#4956 (comment)

@bastimeyer
Copy link
Member Author

Regarding the fix for encrypted HLS streams, this causes the HTTPSession to re-download the faulty/truncated segment. If the server however continues to respond with an incorrect Content-Length header or truncated response body, then there's not much that can be done.

@marmeladema
Copy link

I have installed a patched version of streamlink and will report here in the next couple of days if I encounter the issue again.

@marmeladema
Copy link

I think this solved the issue! Thank you!

@bastimeyer bastimeyer deleted the plugin/api/http_session/enforce-content-length branch June 4, 2021 19:48
@rootxran
Copy link

rootxran commented Jan 16, 2022

I think this solved the issue! Thank you!

Resolves #2365

This should resolve #2365, but I can't validate it myself with data of real HLS streams and don't want to spend time writing sophisticated tests for the entire upstream stack where this bug occurs.

See psf/requests#4956 (comment)

ERROR = Padding is incorrect

How can I solve this problem in streamlink 3.0.3

streamlink --http-header "User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36" --http-header "Referer=https://www.log2base2.com/" "https://d2bzjah96pmxyc.cloudfront.net/C/Functions/Recursion/index.m3u8" best -l debug -o rec.ts
[cli][debug] OS:         Windows 10
[cli][debug] Python:     3.9.8
[cli][debug] Streamlink: 3.0.3
[cli][debug] Requests(2.26.0), Socks(1.7.1), Websocket(1.2.1)
[cli][debug] Arguments:
[cli][debug]  url=https://d2bzjah96pmxyc.cloudfront.net/C/Functions/Recursion/index.m3u8
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --output=rec.ts
[cli][debug]  --ffmpeg-ffmpeg=C:\Program Files (x86)\Streamlink\ffmpeg\ffmpeg.exe
[cli][debug]  --http-header=[('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'), ('Referer', 'https://www.log2base2.com/')]
[cli][info] Found matching plugin hls for URL https://d2bzjah96pmxyc.cloudfront.net/C/Functions/Recursion/index.m3u8
[plugins.hls][debug] URL=https://d2bzjah96pmxyc.cloudfront.net/C/Functions/Recursion/index.m3u8; params={}
[utils.l10n][debug] Language code: en_GB
[stream.hls][debug] Using external audio tracks for stream 1080p (language=None, name=Default)
[stream.hls][debug] Using external audio tracks for stream 1080p_alt (language=None, name=Default)
[stream.hls][debug] Using external audio tracks for stream 576p (language=None, name=Default)
[stream.hls][debug] Using external audio tracks for stream 360p (language=None, name=Default)
[stream.hls][debug] Using external audio tracks for stream 224p (language=None, name=Default)
[stream.hls][debug] Using external audio tracks for stream 73k (language=None, name=Default)
[cli][info] Available streams: 73k (worst), 224p, 360p, 576p, 1080p_alt, 1080p (best)
[cli][info] Opening stream: 1080p (hls-multi)
[stream.ffmpegmux][debug] Opening hls substream
[stream.hls][debug] Reloading playlist
[stream.ffmpegmux][debug] Opening hls substream
[stream.hls][debug] Reloading playlist
[utils.named_pipe][info] Creating pipe streamlinkpipe-9412-1-4873
[utils.named_pipe][info] Creating pipe streamlinkpipe-9412-2-2555
[stream.ffmpegmux][debug] ffmpeg command: C:\Program Files (x86)\Streamlink\ffmpeg\ffmpeg.exe -nostats -y -i \\.\pipe\streamlinkpipe-9412-1-4873 -i \\.\pipe\streamlinkpipe-9412-2-2555 -c:v copy -c:a copy -map 0:v? -map 0:a? -map 1:a -f mpegts pipe:1
[stream.ffmpegmux][debug] Starting copy to pipe: \\.\pipe\streamlinkpipe-9412-1-4873
[stream.ffmpegmux][debug] Starting copy to pipe: \\.\pipe\streamlinkpipe-9412-2-2555
[cli][debug] Pre-buffering 8192 bytes
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] First Sequence: 0; Last Sequence: 24
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 0; End Sequence: 24
[stream.hls][debug] Adding segment 0 to queue
[stream.hls][debug] Adding segment 1 to queue
[stream.hls][debug] Adding segment 2 to queue
[stream.hls][debug] Adding segment 3 to queue
[stream.hls][debug] Adding segment 4 to queue
[stream.hls][debug] Adding segment 5 to queue
[stream.hls][debug] Adding segment 6 to queue
[stream.hls][debug] Adding segment 7 to queue
[stream.hls][debug] Adding segment 8 to queue
[stream.hls][debug] Adding segment 9 to queue
[stream.hls][debug] Adding segment 10 to queue
[stream.hls][debug] Adding segment 11 to queue
[stream.hls][debug] Adding segment 12 to queue
[stream.hls][debug] Adding segment 13 to queue
[stream.hls][debug] Adding segment 14 to queue
[stream.hls][debug] Adding segment 15 to queue
[stream.hls][debug] Adding segment 16 to queue
[stream.hls][debug] Adding segment 17 to queue
[stream.hls][debug] Adding segment 18 to queue
[stream.hls][debug] Adding segment 19 to queue
[stream.hls][debug] Adding segment 20 to queue
[stream.hls][debug] Adding segment 21 to queue
[stream.hls][debug] Segments in this playlist are encrypted
[stream.hls][debug] First Sequence: 0; Last Sequence: 25
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 0; End Sequence: 25
[stream.hls][debug] Adding segment 0 to queue
[stream.hls][debug] Adding segment 1 to queue
[stream.hls][debug] Adding segment 2 to queue
[stream.hls][debug] Adding segment 3 to queue
[stream.hls][debug] Adding segment 4 to queue
[stream.hls][debug] Adding segment 5 to queue
[stream.hls][debug] Adding segment 6 to queue
[stream.hls][debug] Adding segment 7 to queue
[stream.hls][debug] Adding segment 8 to queue
[stream.hls][debug] Adding segment 9 to queue
[stream.hls][debug] Adding segment 10 to queue
[stream.hls][debug] Adding segment 11 to queue
[stream.hls][debug] Adding segment 12 to queue
[stream.hls][debug] Adding segment 13 to queue
[stream.hls][debug] Adding segment 14 to queue
[stream.hls][debug] Adding segment 15 to queue
[stream.hls][debug] Adding segment 16 to queue
[stream.hls][debug] Adding segment 17 to queue
[stream.hls][debug] Adding segment 18 to queue
[stream.hls][debug] Adding segment 19 to queue
[stream.hls][debug] Adding segment 20 to queue
[stream.hls][debug] Adding segment 21 to queue
[stream.hls][debug] Segment 0 complete
[stream.hls][debug] Adding segment 22 to queue
Exception in thread Thread-HLSStreamWriter:
[stream.hls][debug] Segment 0 complete
Traceback (most recent call last):
  File "threading.py", line 973, in _bootstrap_inner
[stream.hls][debug] Adding segment 22 to queue
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink\stream\segmented.py", line 200, in run
    self.write(segment, result, *data)
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink\stream\hls.py", line 162, in write
    return self._write(sequence, *args, **kwargs)
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink\stream\hls.py", line 192, in _write
    chunk = unpad(decrypted_chunk, AES.block_size, style="pkcs7")
  File "C:\Program Files (x86)\Streamlink\pkgs\Crypto\Util\Padding.py", line 92, in unpad
    raise ValueError("Padding is incorrect.")
ValueError: Padding is incorrect.
[cli][debug] Checking file output
[cli][debug] Writing stream to output
[stream.ffmpegmux][debug] Pipe copy complete: \\.\pipe\streamlinkpipe-9412-1-4873
Exception in thread Thread-HLSStreamWriter:
Traceback (most recent call last):
  File "threading.py", line 973, in _bootstrap_inner
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink\stream\segmented.py", line 200, in run
    self.write(segment, result, *data)
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink\stream\hls.py", line 162, in write
    return self._write(sequence, *args, **kwargs)
  File "C:\Program Files (x86)\Streamlink\pkgs\streamlink\stream\hls.py", line 192, in _write
    chunk = unpad(decrypted_chunk, AES.block_size, style="pkcs7")
  File "C:\Program Files (x86)\Streamlink\pkgs\Crypto\Util\Padding.py", line 92, in unpad
    raise ValueError("Padding is incorrect.")
ValueError: Padding is incorrect.

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

Successfully merging this pull request may close these issues.

How to avoid "Input is not padded or padding is corrupt" error?
4 participants