This one comes up a lot: a transcript script works on your laptop every time, then you deploy it and every request comes back RequestBlocked. Same code, same video, different machine.
If you're seeing RequestBlocked or IpBlocked from youtube-transcript-api on AWS, GCP, Render, Fly or a CI runner, it's almost certainly not your code. It's where the request comes from. The library's README says it directly: "YouTube has started blocking most IPs that are known to belong to cloud providers."
Check that it really is the server's IP
Run the plainest possible fetch on both machines:
from youtube_transcript_api import YouTubeTranscriptApi
ytt_api = YouTubeTranscriptApi()
transcript = ytt_api.fetch("jNQXAC9IVRw")
print(transcript.snippets[0].text)
If it prints on your laptop and raises RequestBlocked / IpBlocked on the server, you're looking at the cloud IP block. Retrying, upgrading the library or changing headers won't move it for long. yt-dlp downloads hit the same wall from the same hosts, for the same reason.
The fix the library documents: route through a residential proxy
The library has proxy support built in for exactly this. With Webshare:
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.proxies import WebshareProxyConfig
ytt_api = YouTubeTranscriptApi(
proxy_config=WebshareProxyConfig(
proxy_username="<proxy-username>",
proxy_password="<proxy-password>",
)
)
ytt_api.fetch("jNQXAC9IVRw")
Or any provider through GenericProxyConfig:
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.proxies import GenericProxyConfig
ytt_api = YouTubeTranscriptApi(
proxy_config=GenericProxyConfig(
http_url="http://user:pass@my-proxy.example:port",
https_url="https://user:pass@my-proxy.example:port",
)
)
The part that trips people up: the kind of proxy
A common way this goes wrong: the proxy is set up, requests are still blocked, and it looks like proxies don't work. Usually it's the cheap plan. A datacenter proxy is still a datacenter IP, so YouTube treats it the same as your server. The library's setup notes are explicit that you want the residential package, and to make sure NOT to purchase "Proxy Server" or "Static Residential". Free proxy tiers are datacenter IPs too.
Rotating residential works. It also means you now pay for metered bandwidth, keep the account topped up, and watch for the day the pool you're on gets flagged. That's fine for a lot of projects. It's just worth knowing it's an ongoing thing you run, not a one-line change.
Videos with no captions
One more thing that shows up once real users paste real links: youtube-transcript-api reads caption tracks that already exist. A video with no captions, or a podcast or a site without them, gives you nothing. Covering those means running speech-to-text on the audio, which is a second pipeline on the server.
What I'd do
On your own machine, or for a small script, the library is free and works well. Use it.
If it's running inside an app on a server and you'd rather not run the proxy side yourself, that's the case I built Importly for (disclosure: it's my product). Your server sends the link and gets the transcript back with timestamps, with speech-to-text when there are no captions, and it's free to try: https://www.importly.io/blog/youtube-transcript-python?utm_source=devto&utm_medium=article&utm_campaign=syndication&utm_content=transcripts-cloud-ip
The full guide, with related server errors, is on ytdlp.org: https://ytdlp.org/guides/youtube-transcripts-cloud-ip-blocking
Top comments (0)