I am on Python 3.12 and use Pytube 15.0.0 and have written a small charts downloader.
Until a few days ago everything worked fine, but now YouTube must have changed something and I get the http error message “403 Forbidden” when I try to download. I download the audio_only stream with Pytube. I have tried the solutions mentioned in previous posts, but neither changing the user agent in the innertube.py file to WEB or ANDROID nor completely uninstalling and reinstalling Pytube worked or improved the situation.
Does anyone here have a solution to the problem? Are there any other modules for Python to download clips from Youtube? Many thanks in advance for your suggestions.
I had the same issue with pytube giving an HTTP 403 error. I switched to yt-dlp, but then got this error:
ERROR: [youtube] XCZWyN9ZbEQ: Sign in to confirm you’re not a bot. Use --cookies-from-browser or --cookies for the authentication.
1 - Use the 'Get Cookies.txt' extension in Chrome to export cookies to a cookies.txt file from a logged-in session.
Then simply pass it into ydl options like below:
ydl_opts = {'outtmpl': f"{output_path}/%(title)s.%(ext)s", 'cookiefile': 'cookies.txt'}
2 - Else you can use this option to load cookies directly from browser:
ydl_opts = {'outtmpl': f"{output_path}/%(title)s.%(ext)s", 'cookiesfrombrowser': ('chrome',)}
Both worked fine for me.
Hope it can help you.
Enjoy :)