Django app YouTube transcript extraction fails on cloud hosting but works locally

I’m having a weird issue with my Django application. I built a feature to get YouTube video transcripts using the youtube-transcript-api library. Everything runs smoothly when I test it on my local machine, but as soon as I deploy to my cloud server (using DigitalOcean App Platform), it breaks.

from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound, VideoUnavailable

def get_video_transcript(yt_url):
    vid_id = yt_url.split("v=")[-1]
    print(f"Processing video ID: {vid_id}")

    try:
        available_transcripts = YouTubeTranscriptApi.list_transcripts(vid_id)
        final_transcript = None
        
        for trans in available_transcripts:
            try:
                final_transcript = trans.fetch()
                break
            except Exception as error:
                print(f"Failed to get transcript: {error}")
                continue
                
        if final_transcript is None:
            return "Cannot find any transcripts for this video"
            
    except TranscriptsDisabled:
        return "This video has transcripts disabled"
    except NoTranscriptFound:
        return "No transcript exists for this video"
    except VideoUnavailable:
        return "This video is not available"
    except Exception as error:
        return f"Something went wrong: {error}"
    
    full_text = ' '.join([entry['text'] for entry in final_transcript])
    return full_text

The problem happens right at available_transcripts = YouTubeTranscriptApi.list_transcripts(vid_id). It throws a TranscriptsDisabled error saying the video doesn’t have transcripts available. But I know for sure the video has transcripts because it works fine locally and I can see them on YouTube.

I’ve been stuck on this for days now and tried everything I can think of. Has anyone run into this same problem and found a way to fix it?

yea I’ve had the same issue b4! it could be the server ip is getting blocked by youtube. try using a different server or a proxy to test it. also, check if you’re hitting any rate limits; that can cause weird issues too.

This is definitely a geographic restriction or IP blocking issue. YouTube’s API treats server locations and IP reputation differently. DigitalOcean datacenters use shared IP ranges that YouTube often flags as suspicious because of automated traffic from other users.

I ran into the same thing on AWS - videos worked fine locally but failed in production. What fixed it for me was rotating user agents and adding random delays between requests.

Try switching to a different DigitalOcean region or see if they offer IP rotation. Also double-check that your production environment has the same python package versions as your local setup. Updates to youtube-transcript-api sometimes change how it handles edge cases.

Had this exact problem moving my Django app from local to Heroku. It’s not just IP blocking - SSL certificate validation and DNS resolution work differently between your local machine and cloud infrastructure. Some cloud platforms use DNS resolvers that YouTube’s CDN doesn’t trust.

I fixed it with a retry mechanism using exponential backoff and switched requests to use a custom session with proper headers. Also check if your cloud provider runs behind a NAT or firewall that’s messing with your requests. DigitalOcean App Platform has networking quirks that mess with external API calls sometimes. Test the same code on a basic droplet first to see if it’s the platform or IP range causing problems.