Skip to content

Youtube is detecting request as a bot, but only in cloud application #459

Open
@limatila

Description

@limatila

🐞 Bug Description

Youtube is blocking my requests (with poToken validation, client set to 'WEB') from a remote cloud AWS server running my API that uses Pytubefix. In fact, it only seems to be rejecting requests from the AWS instance, as currently at my computer (on localhost) it is running smoothly, downloading files as intended.

I just wanted to make this a public service, but it seems that i'll need to keep it as localhost or change my dependency...

🔢 Code Snippet

Include the minimal code snippet that reproduces the issue.

def download_raw_audio(url: str) -> Path:
    try:
        yt_Client = YouTube(url, 'WEB', on_progress_callback=on_progress)
    except RegexMatchError:
        raise HTTPException(status_code=400, detail={
            "error": "the video url is invalid, please copy a proper video url from youtube client",
            "inserted_link": url
        })
    except VideoUnavailable:
        raise HTTPException(status_code=404, detail={
            "error": "Youtube video was not found with the inserted link.",
            "inserted_link": url,
            "hint": "try using another link, you can copy it from any youtube video"
        })
    except:
        raise HTTPException(status_code=500, detail="Your video could not be resolved by the download service. Please try another video url!")

    downloadsFolderPath = Path("./temp-downloads/") #path to temp files
    if not downloadsFolderPath.is_dir():
        downloadsFolderPath.mkdir()

    if yt_Client: 
        print("INFO: Video found: " + yt_Client.title)

    yt_AudioStream = yt_Client.streams.get_audio_only()
    # [...]

🎯 Expected Behavior

I'm just trying to download audio from the youtube url as my client wishes. Later processing will be done, but nothing to deal with this library.


📸 Screenshots or Logs

File "/home/ubuntu/Clean-Converter-API/venv/lib/python3.12/site-packages/pytubefix/__main__.py", line 401, in check_availability
    raise exceptions.BotDetection(video_id=self.video_id)
pytubefix.exceptions.BotDetection: tGD3653BrZ8 This request was detected as a bot. Use `use_po_token=True` or switch to WEB client to view. See more details at https://github.com/JuanBindez/pytubefix/pull/2093

🖥️ Environment Details

Fill in the details below about your setup:

  • Operating System: Windows 10
  • Python Version: 3.12.3
  • Pytubefix Version: 8.12.3

📋 Additional Context

I already double checked for any faults in bot_guard.py, if it was correctly loading Node, and executing the script with a valid answer... Additionally, i locally logged the visitorData and poToken, and the two tokens are correctly generated:

-------
visitorData: CgtLeEpubEFhemU4USilkLu_BjInCgJTRRIhEh0SGwsMDg8QERITFBUWFxgZGhscHR4fICEiIyQlJiAp 
poToken: MpgB9oU5mWzwceX2uXm3dc69k9TNzBRDEE6Xi7lSHKd8UdMcZZvsYBOlm4NQGX_BBexoM-CB66Xom5PypMDDKtFOhvQhgvwP0yoBh18m5tQX_xFZcx8PFBAeHf3AGltvX1w-LOPfZzUa0Bd3ub_SiED4rjpUzmjIyi8_fWfRLgywgIUT7f-ccidW341xRn-HzmfC5WXUWrZ6aQE=

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    waiting

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions