Add PoToken¶
The proof of origin (PO) token is a parameter that YouTube requires to be sent with video playback requests from some clients. Without it, format URL requests from affected customers may return HTTP error 403, error with bot detection, or result in your account or IP address being blocked.
This token is generated by BotGuard (Web) / DroidGuard (Android) to attest the requests are coming from a genuine client. This guide will be assuming the use of a PO Token generated by BotGuard, for use with the web client.
Automatic PO Token generation with nodejs¶
Pytubefix has the ability to generate a PoToken automatically, all you need to have is nodejs installed on your machine and change the client to some poToken client, for example the WEB client:
from pytubefix import YouTube
url = input("url >")
yt = YouTube(url, 'WEB')
print(yt.title)
ys = yt.streams.get_highest_resolution()
ys.download()
If you don’t have nodejs or can’t install it, don’t worry, it’s possible to manually pass a PoToken.
Manually acquiring a PO Token from a browser for use when logged out¶
This process involves manually obtaining a PO token generated from YouTube in a web browser and then manually passing it to pytubefix via the use_po_token=True
argument.
Steps:
Open a browser and go to any video on YouTube Music or YouTube Embedded (e.g. https://www.youtube.com/embed/aqz-KE-bpKQ). Make sure you are not logged in to any account!
Open the developer console (F12), then go to the “Network” tab and filter by v1/player
Click the video to play and a player request will appear in the network tab
In the request payload JSON, find the PO Token at serviceIntegrityDimensions.poToken and save that value
In the request payload JSON, find the visitorData at context.client.visitorData and save that value
In the pytubefix code, pass the parameter
use_po_token=True
, to send the visitorData and PoToken:
from pytubefix import YouTube
url = input("url >")
yt = YouTube(url, use_po_token=True)
print(yt.title)
ys = yt.streams.get_highest_resolution()
ys.download()
FAQ¶
Detected as a bot even using PoToken¶
The main purpose of passing PO Token is to help prevent getting blocked (if on non-DC IP) and allow formats from web clients to work.
If you are being detected as a bot even after passing the PoToken, there are only two alternatives:
If even after these attempts you continue to be detected, unfortunately there is nothing we can do.
Do I need to do any configuration in nodejs?¶
All you need to do is install nodejs and make sure to put it in your system path, pytubefix will automatically call it using the node
environment variable