Pytube common error while downloading video PYTHON
Question:
I am trying to download a YouTube video using pytube
but i get the error bellow, this error has been mentioned in stack overflow many times but almost all of them are outdated.
This and this questions are having the same problems and are left unanswered.
This question has been answered here and here but the answered appears to be outdated and so it does not work anymore.
Error:
Traceback (most recent call last):
File "C:UserskeiboPycharmProjectsbot2Locationmain.py", line 60, in <module>
DownloadVideo(f'{(Main.get("result")[int(choice)]).get("id")}')
File "C:UserskeiboPycharmProjectsbot2Locationmain.py", line 22, in DownloadVideo
video_stream = yt.streams.get_highest_resolution()
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytube__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytube__main__.py", line 181, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytubeextract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytubecipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytubecipher.py", line 411, in get_throttling_plan
transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
AttributeError: 'NoneType' object has no attribute 'span'
Process finished with exit code 1
Code:
def DownloadVideo(ID):
yt = YouTube(f'https://www.youtube.com/watch?v={ID}')
video_stream = yt.streams.get_highest_resolution()
video_stream.download(output_path='OutPut', filename=f'{ID}.mp4')
Answers:
This error might because of a modification in youtube cipher algorithm or something else, you can still try with pytube
but you will be better with an alternative library like the way more used and updated yt-dlp
with pip install yt-dlp
still you can try to install the last version with pip install --upgrade pytube
I am trying to download a YouTube video using pytube
but i get the error bellow, this error has been mentioned in stack overflow many times but almost all of them are outdated.
This and this questions are having the same problems and are left unanswered.
This question has been answered here and here but the answered appears to be outdated and so it does not work anymore.
Error:
Traceback (most recent call last):
File "C:UserskeiboPycharmProjectsbot2Locationmain.py", line 60, in <module>
DownloadVideo(f'{(Main.get("result")[int(choice)]).get("id")}')
File "C:UserskeiboPycharmProjectsbot2Locationmain.py", line 22, in DownloadVideo
video_stream = yt.streams.get_highest_resolution()
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytube__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytube__main__.py", line 181, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytubeextract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytubecipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:UserskeiboPycharmProjectsbot2venvlibsite-packagespytubecipher.py", line 411, in get_throttling_plan
transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
AttributeError: 'NoneType' object has no attribute 'span'
Process finished with exit code 1
Code:
def DownloadVideo(ID):
yt = YouTube(f'https://www.youtube.com/watch?v={ID}')
video_stream = yt.streams.get_highest_resolution()
video_stream.download(output_path='OutPut', filename=f'{ID}.mp4')
This error might because of a modification in youtube cipher algorithm or something else, you can still try with pytube
but you will be better with an alternative library like the way more used and updated yt-dlp
with pip install yt-dlp
still you can try to install the last version with pip install --upgrade pytube