[Python] Python flask application works locally and not on Digital ocean VPS

Discussão em 'Python' iniciado por Stack, Janeiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm experiencing an issue with the youtube_transcript_api library. The API works perfectly fine on my local machine, where I can retrieve YouTube video transcripts without any problems. However, when I deploy the same Flask application on my VPS, I encounter the error:

    "Could not retrieve transcript. The video might not have captions."

    Interestingly, the error occurs for all YouTube links, even those that work perfectly on my local machine.

    Here's the relevant code I'm using:

    ```from youtube_transcript_api import YouTubeTranscriptApi
    import re

    def extract_video_id(url):
    regex = r"(?:v=|\/)([0-9A-Za-z_-]{11}).*"
    match = re.search(regex, url)
    return match.group(1) if match else None

    def get_transcript(url):
    video_id = extract_video_id(url)
    if not video_id:
    return None
    try:
    transcript = YouTubeTranscriptApi.get_transcript(video_id)
    return ' '.join([t['text'] for t in transcript])
    except:
    return None```


    Problem: The same URL (https://www.youtube.com/watch?v=y_cpFMF1pzk or others) that works locally doesn't work on the VPS. The error message is: "Could not retrieve transcript. The video might not have captions." The error occurs for all URLs tested on the VPS. Things I’ve Tried: Network Issues: I confirmed that my VPS has internet access and can reach external services (e.g., I can access the video via curl without issues). YouTube's Captions Availability: I manually checked that the video indeed has captions, as I can retrieve them from my local environment. Firewall and Network Restrictions: I checked if there were any firewall or security restrictions on my VPS, but they don't seem to be the cause.

    What I'm Looking For: Why is the transcript retrieval working locally but not on the VPS? Are there any configuration or network-related issues that could be affecting the API's ability to fetch transcripts? Any suggestions or insights into why this might be happening, or how to fix it? Thank you for any help!

    Things I’ve Tried: Network Issues: I confirmed that my VPS has internet access and can reach external services (e.g., I can access the video via curl without issues). YouTube's Captions Availability: I manually checked that the video indeed has captions, as I can retrieve them from my local environment. Firewall and Network Restrictions: I checked if there were any firewall or security restrictions on my VPS, but they don't seem to be the cause.

    something to note is that the VPS is hosted in New york im not sure if this would cause any issues with accessing the link.

    You may be able to use my web app here http://209.97.144.80:5000/

    Continue reading...

Compartilhe esta Página