Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't solve cloudflare captcha inside a VM #3628

Closed
gab-i-alves opened this issue Mar 24, 2025 · 5 comments
Closed

Can't solve cloudflare captcha inside a VM #3628

gab-i-alves opened this issue Mar 24, 2025 · 5 comments
Labels
duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@gab-i-alves
Copy link

gab-i-alves commented Mar 24, 2025

I have the following code, that works when running locally, but when I try to run inside a VM it can't be solved, any tips on how to solve the problem?

I used both sb.activate_cdp_mode and sb.uc_open_with_reconnect to open the site, and sb.uc_gui_handle_captcha()/ sb.uc_gui_handle_cf() to solve the captcha, neither work.


def login(self, sb):
        """Realiza o login no site."""
        sb.activate_cdp_mode(SITE_URL)
        # sb.uc_open_with_reconnect(SITE_URL)

        sb.press_keys("#txtUsuario", self.username)
        sb.press_keys("#pwdSenha", self.password)
        sb.click("#sbmEntrar")

    def solve_captcha(self, sb):
        """Resolve o captcha da Cloudflare enquanto ele estiver presente."""

        try:
            sb.sleep(5)
            while sb.is_element_visible('div[class*="cf-turnstile"]'):
                logger.info("Captcha detectado! Resolvendo...")

                sb.sleep(5)
                sb.scroll_to('div[class*="cf-turnstile"]')
                sb.uc_gui_handle_captcha()
                # sb.uc_gui_handle_cf()

                sb.sleep(2)

                if sb.is_element_visible(".eproc-button-primary"):
                    sb.click(".eproc-button-primary")
                    sb.sleep(2)

            logger.info("Cloudflare des-tru-í-do.")

        except Exception as e:
            logger.error(f"Erro ao resolver o captcha: {e}")

Image

Edit: These are the options on the SB:

with SB(
            uc=True,
            test=True,
            ad_block=True,
            headed=True,
            headless=False,
            external_pdf=True,
            disable_csp=True,
        ) as sb:
@mdmintz mdmintz added duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode invalid usage You may need to change what you're doing labels Mar 24, 2025
@mdmintz
Copy link
Member

mdmintz commented Mar 24, 2025

Duplicate of #3449 (comment).

  • CDP Mode replaces regular UC Mode.
  • Docker leaves a detectable fingerprint.

@mdmintz mdmintz closed this as completed Mar 24, 2025
@gab-i-alves
Copy link
Author

Thanks for the answer but I'm not running on docker, the virtual machine was made on virtual box and it's running linux mint with a graphical interface.
I only CPD methods on my code. Here are more info about the VM:

Linux Kernel: 5.15.0-86-generic

Selenium Base version:
Name: seleniumbase
Version: 4.36.1
Summary: A complete web automation framework for end-to-end testing.
Home-page: https://github.com/seleniumbase/SeleniumBase
Author: Michael Mintz
Author-email: mdmintz@gmail.com
License: MIT
Location: /home/robo/.local/lib/python3.10/site-packages
Requires: attrs, beautifulsoup4, behave, certifi, chardet, charset-normalizer, colorama, cssselect, exceptiongroup, execnet, fasteners, filelock, h11, idna, iniconfig, Jinja2, markdown-it-py, MarkupSafe, mdurl, mycdp, outcome, packaging, parameterized, parse, parse-type, pdbp, pip, platformdirs, pluggy, pygments, pynose, pyotp, pytest, pytest-html, pytest-metadata, pytest-ordering, pytest-rerunfailures, pytest-xdist, python-xlib, pyyaml, requests, rich, sbvirtualdisplay, selenium, setuptools, six, sniffio, sortedcontainers, soupsieve, tabcompleter, trio, trio-websocket, typing-extensions, urllib3, websocket-client, websockets, wheel, wsproto
Required-by:

Selenium version:

Name: selenium
Version: 4.30.0
Summary: Official Python bindings for Selenium WebDriver
Home-page: https://www.selenium.dev
Author: 
Author-email: 
License: Apache 2.0
Location: /home/robo/.local/lib/python3.10/site-packages
Requires: certifi, trio, trio-websocket, typing_extensions, urllib3, websocket-client
Required-by: seleniumbase, undetected-chromedriver

Chromium version:
Chromium 118.0.5993.70 for Linux Mint

The SB options:

with SB(
            uc=True,
            test=True,
            ad_block=True,
            headed=True,
            headless=False,
            external_pdf=True,
            disable_csp=True,
            xvfb=True,
        ) as sb:

On the code, I open the URL with cdp mode and to click on the captcha, I'm using the pyautogui method sb.uc_gui_handle_captcha()

Thanks for the help!

@mdmintz
Copy link
Member

mdmintz commented Mar 25, 2025

Docker or not, virtual machines leave a fingerprint unless properly configured, and that virtual machine configuration is not something that's part of SeleniumBase.

You would need to properly configure your Linux Mint machine to make it look like a regular Linux desktop.
From there, SeleniumBase will do it's job and make your web browser appear human-controlled.

And as I mentioned earlier, CDP Mode replaces regular UC Mode.

@mdmintz
Copy link
Member

mdmintz commented Mar 25, 2025

It might not be the machine configuration though. If that machine is hosted on a non-residential IP range, then it would get blocked due to that.

@gab-i-alves
Copy link
Author

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants