Fix RequestBlocked in youtube-transcript-api
Your script works on your laptop, you deploy it, and every call fails with RequestBlocked or IpBlocked. Here's why it happens and the three ways to fix it.
The error
The exception is youtube_transcript_api._errors.RequestBlocked (or its subclass IpBlocked), and its message explains that YouTube is blocking requests from your IP, either because of too many requests or because the IP belongs to a cloud provider such as AWS, Google Cloud or Azure.
Why it happens
YouTube blocks most IP ranges that belong to cloud providers, because that's where scrapers run. It doesn't matter how few requests you make: the IP is flagged before you start. That's why the same code works at home and fails on AWS, Google Cloud, Azure, Hetzner, DigitalOcean, Vercel, Render or GitHub Actions.
Fix 1: rotating residential proxies
The library supports proxies directly, and its README recommends rotating residential ones (not "static residential" or datacenter proxies). With Webshare:
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.proxies import WebshareProxyConfig
api = YouTubeTranscriptApi(proxy_config=WebshareProxyConfig(
proxy_username="...", proxy_password="...",
))
api.fetch("dQw4w9WgXcQ")
Other providers work with GenericProxyConfig(http_url=..., https_url=...). Expect a monthly subscription billed by bandwidth, occasional failures that need retries, and some monitoring.
Fix 2: run it from a non-cloud IP
For small personal projects, run the job from a home machine or a Raspberry Pi and push the results to your server. Cheap, but it depends on your home connection and doesn't scale.
Fix 3: use a hosted transcript API
A hosted API runs the proxies for you. With Transkrio it's one request from anywhere, failed requests are free, and results are cached:
import os, requests
r = requests.get("https://api.transkrio.com/v1/transcript",
params={"url": "dQw4w9WgXcQ"},
headers={"x-api-key": os.environ["TRANSKRIO_API_KEY"]})
segments = r.json()["segments"] # text, start, duration
The free key includes 100 transcripts, enough to check that it solves your problem. Compare the options in library vs hosted API or see all YouTube transcript APIs.
Which fix to choose
- Hobby project, low volume: fix 2, or a hosted API's free tier.
- Production app, up to tens of thousands a month: a hosted API is usually cheaper than proxies plus your time.
- Very high volume, in-house infrastructure: fix 1, with good retry logic.