question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] A very short video has an error.

See original GitHub issue

Describe the bug A very short video has an error.

The request used for the download does not seem to be able to handle requests for a small capacity. The urllib in use in the pytube package cannot handle this. The error contents are as follows.

To Reproduce Please provide the following information:

Traceback (most recent call last):
  File "/home/jayflow/Proejcts/Puzz/video_cron/venv/lib/python3.10/site-packages/rq/worker.py", line 1061, in perform_job
    rv = job.perform()
  File "/home/jayflow/Proejcts/Puzz/video_cron/venv/lib/python3.10/site-packages/rq/job.py", line 821, in perform
    self._result = self._execute()
  File "/home/jayflow/Proejcts/Puzz/video_cron/venv/lib/python3.10/site-packages/rq/job.py", line 844, in _execute
    result = self.func(*self.args, **self.kwargs)
  File "/home/jayflow/Proejcts/Puzz/video_cron/src/providers/youtube.py", line 32, in download_video
    YouTube(
  File "/home/jayflow/Proejcts/Puzz/video_cron/venv/lib/python3.10/site-packages/pytube/streams.py", line 252, in download
    for chunk in request.stream(
  File "/home/jayflow/Proejcts/Puzz/video_cron/venv/lib/python3.10/site-packages/pytube/request.py", line 185, in stream
    chunk = response.read()
  File "/usr/lib/python3.10/http/client.py", line 481, in read
    s = self._safe_read(self.length)
  File "/usr/lib/python3.10/http/client.py", line 632, in _safe_read
    raise IncompleteRead(data, amt-len(data))
http.client.IncompleteRead: IncompleteRead(0 bytes read, 203085 more expected)

image

My code

YouTube(
    url=f'https://www.youtube.com/watch?v={video_id}',
    on_complete_callback=lambda stream, file_path:
    self.__on_complete_download(
        YouTubeVideoMeta(
            video_id=video_id,
            file_path=file_path,
            file_name=file_path.split('/')[-1],
            stream=stream,
        ),
    ),
    on_progress_callback=self.__show_download_progress
).streams.get_highest_resolution().download(video_storage_path, filename=file_name)

System information Please provide the following information:

  • Python version (run python --version) Python 3.10.2

  • Pytube version (run print(pytube.__version__) in python) pytube==12.0.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
dongyouhongcommented, Jul 17, 2022

Modify the /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/request.py file as follows: 图片

it’s ok

2reactions
Spositocommented, May 20, 2022

I am having the same issue here

Traceback (most recent call last):
  File "/Users/thiago/PycharmProjects/Youtube-whatsapp-bridge/main.py", line 51, in <module>
    stream.download(f'videos/{vid_id}')
  File "/Users/thiago/PycharmProjects/Youtube-whatsapp-bridge/venv/lib/python3.9/site-packages/pytube/streams.py", line 252, in download
    for chunk in request.stream(
  File "/Users/thiago/PycharmProjects/Youtube-whatsapp-bridge/venv/lib/python3.9/site-packages/pytube/request.py", line 185, in stream
    chunk = response.read()
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 476, in read
    s = self._safe_read(self.length)
  File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 628, in _safe_read
    raise IncompleteRead(b''.join(s), amt)
http.client.IncompleteRead: IncompleteRead(0 bytes read, 7350689 more expected)

Is there any reason for using a low-level library like http.client, instead of something more straightforward like requests?

Read more comments on GitHub >

github_iconTop Results From Across the Web

20 most common video errors & how to fix them
This article guide you how to fix all 20 problems or errors while playing videos like playback errors, audio video sync, issues, choppy, ......
Read more >
Common uploading errors - YouTube Help - Google Support
This error message may occur if the uploaded file is shortened or invalid. It can also occur on reduced upload speeds. Try playing...
Read more >
[Update: Dec. 16] YouTube bugs/issues & pending ...
An error message “endscreen element is too small” always popped up on trying to do so. Again, as it stands, YouTube today fixed...
Read more >
Display Problems Playing Video Clips in Windows
RESOLUTION · Removing and Reinstalling Video Compression · Need more help?
Read more >
How to Fix FaceBook Having Issues on Video Playing?
Though, if the video itself has been corrupted, then you can simply try Wondershare Video Repair to fix it. A complete video repairing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found