【问题标题】:"KeyError: 'content-length'" when using PyTube on specific video downloads\"KeyError: \'content-length\'\" when using PyTube on specific video downloads
【发布时间】:2022-12-28 00:11:26
【问题描述】:

I am getting the error

KeyError: 'content-length'

while downloading videos. Specifically for this one, whenever I try to download this video in 1080p, I get the error.

To Reproduce

Try downloading this video in 1080p resolution with pytube. https://www.youtube.com/watch?v=6PDxyCLaTeU

Code

from pytube import YouTube
yt = YouTube("https://www.youtube.com/watch?v=6PDxyCLaTeU")

yt.streams.filter(resolution="1080p").first().download()

Exception

return int(head(url)["content-length"])
KeyError: 'content-length'

System information

  • Python version : Python 3.9.2
  • Pytube version : 12.0.0
  • Command used to install pytube : pip install pytube

【问题讨论】:

  • Looks like a bug in the library you are using. There isn't much we can do to help, you should report the issue to the maintainers of PyTube. Maybe include the full backtrace when you do.
  • @MarcoBonelli, Yes I did create a issue in the repo of PyTube, but no response ... that's why created a question here too ... lets see what happens

标签: python pytube


【解决方案1】:

NISHANT Pacharne. I hope this problem is still relevant.

I have already downloaded several hundred videos using pytube, but today is the first time I have faced the same problem. After looking at all the complaints on the Internet, your post here and my case,I can note one common detail - all the videos that cause this problem have video_codec= avc1.64001e.

So if you write print(yt.streams.filter(resolution="1080p").first()), then you will see the fields of the <class 'pytube.streams.Stream'>, among which will be vcodec="avc1.64001e".

Note: actual name of a field is "video_codec", not "vcodec"; "vcodec" is only used for object representation.

How to fix it? I still don't know. Maybe my find will help you.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 2022-12-02
    • 2022-08-12
    • 1970-01-01
    相关资源
    最近更新 更多