Lounys
Lounys

Reputation: 1

PyTube raises an exception when I access streams

(I'm on macos and I use python3.12)

I was just starting to try Pytube but got error when I tried to access streams:

Traceback (most recent call last):
  File "/Volumes/Programmation/Python/Projects/Youtube Downloader/main.py", line 6, in <module>
    print(yt.streams)
          ^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytube/__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
                       ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytube/__main__.py", line 176, in fmt_streams
    stream_manifest = extract.apply_descrambler(self.streaming_data)
                                                ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytube/__main__.py", line 160, in streaming_data
    self.bypass_age_gate()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pytube/__main__.py", line 264, in bypass_age_gate
    raise exceptions.AgeRestrictedError(self.video_id)
pytube.exceptions.AgeRestrictedError: G3e-cpL7ofc is age restricted, and can't be accessed without logging in.

And here's my code:

from pytube import YouTube

yt = YouTube("https://www.youtube.com/watch?v=G3e-cpL7ofc", use_oauth=True, allow_oauth_cache=True)
print(yt.title)
print(yt.streams)

When I read the error message, I tried to set use_oauth to True. I have filled the google authentication; it worked and finally when I restart, it stopped to ask the message and raise directly the error of "age restricted". I have added allow_oauth_cache=True and replaced the video url to an official youtube video but I have the same error… G3e-cpL7ofc is age restricted, and can't be accessed without logging in.

Upvotes: 0

Views: 431

Answers (2)

Migwa
Migwa

Reputation: 1

For me worked downgrading Python from 3.12 to 3.9.16.

There isn't information about Python 3.12 in PyTube docs.

Upvotes: 0

Zein
Zein

Reputation: 3

yt.bypass_age_gate()

Maybe try this?

Upvotes: 0

Related Questions