[BUG] KeyError: 'content-length'
See original GitHub issueDescribe the bug
The download function in 10.4.1 results in a 'content-length'
KeyError.
To Reproduce Here’s my code:
from pytube import YouTube
url = input('URL: ')
yt = YouTube(url)
yt.streams.filter(file_extension='mp4').first().download()
Expected behavior I expect it to download the video.
Output
URL: https://www.youtube.com/watch?v=EbNr015DZbM
Traceback (most recent call last):
File "C:\Users\cmlsc\Desktop\youtube_download.py", line 7, in <module>
yt.streams.filter(file_extension='mp4').first().download()
File "D:\Python38\lib\site-packages\pytube\streams.py", line 251, in download
bytes_remaining = self.filesize
File "D:\Python38\lib\site-packages\pytube\streams.py", line 158, in filesize
self._filesize = request.filesize(self.url)
File "D:\Python38\lib\site-packages\pytube\request.py", line 127, in filesize
return int(head(url)["content-length"])
KeyError: 'content-length'
System information
Please provide the following information:
Python Version: 3.8.6
Pytube Version: 10.4.1
Install Command: D:\Python38\python.exe -m pip install git+https://github.com/pytube/pytube --upgrade
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
"KeyError: 'content-length'" when using PyTube on specific ...
I am getting the error. KeyError: 'content-length'. while downloading videos. Specifically for this one, whenever I try to download this ...
Read more >KeyError: 'content-length' : JT-10823 - YouTrack
Using youtrack-python-api-3.0.2-47 I found the following error: Transfer attachment of H-8: CN0151_02_1024.gif. Traceback (most recent call last):
Read more >pytube filesize() keyerror content-length - You.com - You.com
The bug Iam getting the KeyError: 'content-length' while downloading videos, specifically for this one, when ever I try to download this video in...
Read more >Bountysource
[BUG] KeyError: 'content-length' ... Help and Information. Frequently Asked Questions · Bugs and Feature Requests · Fees ...
Read more >Could not load model from S3 due to 'ContentLength'
Error : <class 'KeyError'>: 'ContentLength' UserWarning: Agent could not be loaded with the provided configuration.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Rather than using “pyt_obj.filesize”, try using “pyt_obj._filesize”. That fixed the “KeyError: ‘content-length’” for me.
I think the issue is in pytube.requests and pytube.streams as both have conflicting keys here
streams.py
self._filesize: Optional[int] = int(stream.get('contentLength', 0))
requests.py `@lru_cache() def filesize(url): “”"Fetch size in bytes of file at given URL
I am also getting the same issue only with the following video, which isn’t a recent video or a livestream:
https://www.youtube.com/watch?v=qT4a73ctcmw