youtube-transcript-api RequestBlocked / IpBlocked: how to fix it
If your Python code stops with this error, YouTube has blocked the IP address your code runs from:
youtube_transcript_api._errors.RequestBlocked:
Could not retrieve a transcript for the video ...
YouTube is blocking requests from your IP.
IpBlocked is a subclass of RequestBlocked, so both mean the same thing and both are fixed the same way.
Why it happens
The library's own error message gives two causes:
- You made too many requests and YouTube blocked your IP.
- Your code runs on a cloud provider such as AWS, Google Cloud or Azure. Most of their IP addresses are blocked, which is why code that works on your laptop can fail as soon as you deploy it.
Adding sleep() or retries won't help on a cloud server, because the address itself is blocked.
Fix 1: change one import
youtube-transcript-unblocked keeps the same fetch() and list() calls and the same objects, but gets each transcript through a hosted scraper, so YouTube never sees your IP.
pip install youtube-transcript-unblocked
export APIFY_TOKEN=apify_api_...
# from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_unblocked import YouTubeTranscriptApi
transcript = YouTubeTranscriptApi().fetch("https://www.youtube.com/watch?v=UF8uR6Z6KLc")
print(" ".join(s.text for s in transcript))
You need a free Apify account for the token (Settings → API & Integrations). It costs $0.003 per transcript, videos without captions are free, and Apify's free plan includes $5 of credit a month.
Fix 2: use rotating residential proxies
This is what the youtube-transcript-api README recommends. YouTube bans static proxies after extended use, so the library's author suggests rotating residential ones. It keeps the original library, but you set up and pay for a proxy service yourself.
Fix 3: call the scraper directly
If you aren't using Python, or want a whole channel or playlist, call the YouTube Transcript Scraper over HTTP:
curl -X POST "https://api.apify.com/v2/acts/wulfcare~youtube-transcript-scraper/run-sync-get-dataset-items" \
-H "Authorization: Bearer $APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"urls": ["https://www.youtube.com/watch?v=UF8uR6Z6KLc"], "languages": ["en"]}'
For a channel, pass its URL and add "maxVideosPerSource": 50.
Which should you use?
For a working codebase on a cloud server, Fix 1 is the smallest change. If you already pay for residential proxies, Fix 2 keeps you on the original library. For a few videos on your own machine, waiting for the block to lift may be enough.