JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
http://pytubefix.rtfd.io/
MIT License
593 stars 85 forks source link

urllib.error.HTTPError: HTTP Error 403: Forbidden when use_po_token=True #286

Open MikrotikIT opened 3 days ago

MikrotikIT commented 3 days ago

Error output

Traceback (most recent call last): File "e:\upload-videos-to-youtube\upload.py", line 51, in out_video_file = download_video(link, lesson_id, lesson_duration) File "e:\upload-videos-to-youtube\download_youtube_video.py", line 40, in download_video out_audio_file = ya.download(output_path=SAVE_PATH) File "e:\upload-videos-to-youtube\venv\lib\site-packages\pytubefix\streams.py", line 373, in download
for chunk in request.stream( File "e:\upload-videos-to-youtube\venv\lib\site-packages\pytubefix\request.py", line 154, in stream
response = _execute_request( File "e:\upload-videos-to-youtube\venv\lib\site-packages\pytubefix\request.py", line 35, in _execute_request return urlopen(request, timeout=timeout) # nosec File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen return opener.open(url, data, timeout) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
response = meth(req, response) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response response = self.parent.error( File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error return self._call_chain(args) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain result = func(args) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbidden

Describe the bug the bug show on use po_token

token_file = { "visitorData": "CgtUY3NnY1duYV................................Q%3D%3D", "po_token": "Kr0IC0VCSDpFcnJvcjpScGMgZm...............................UuanM6Nzk4Njo3MCk=" }

Request Data request url = https://rr2---sn-85axxop9-vnhl.googlevideo.com/videoplayback?...................................... Request Method: GET Status Code: 403 Forbidden

chrome output when visit url: Access to rr2---sn-85axxop9-vnhl.googlevideo.com is denied. You do not have permission to view this page. HTTP ERROR 403

code that was used that resulted in the bug from pytubefix import YouTube from pytubefix.cli import on_progress

SAVE_PATH = "downloaded/"
yt = YouTube(link, on_progress_callback = on_progress, use_po_token=True, token_file='token_file.json')

ya = yt.streams.filter(only_audio=True).order_by('abr').last()
out_audio_file = ya.download(output_path=SAVE_PATH)

ys = yt.streams.get_highest_resolution(progressive=False)
out_video_file = ys.download(output_path=SAVE_PATH)

Desktop :

felipeucelli commented 3 days ago

Try resetting the cache and generating another PoToken and visitorData (they expire after a while), then tell us the result.

MikrotikIT commented 3 days ago

same result

MikrotikIT commented 3 days ago

Try resetting the cache how i can resetting the cache?

felipeucelli commented 3 days ago

Try resetting the cache how i can resetting the cache?

In the pytubefix folder you can find the __cache__ where the tokens are stored, delete it and all its contents.

MikrotikIT commented 3 days ago

not found {7CC1C067-9A4F-49AD-B1C9-5568893B1D65}

MikrotikIT commented 3 days ago

which python version is recommended for use pytubefix

felipeucelli commented 3 days ago

Pytubefix is compatible with python 3.6 or higher.