Skip to content

Can't solve cloudflare captcha inside a VM #3628

@gab-i-alves

Description

@gab-i-alves

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    UC Mode / CDP ModeUndetected Chromedriver Mode / CDP ModeduplicateThe answer/solution already exists somewhereinvalid usageYou may need to change what you're doing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions