1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Cloudfare bypass using 2captcha with request [closed]

Discussão em 'Python' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    I am encountering an issue with my Python script that uses the 2Captcha API to solve a Cloudflare Turnstile CAPTCHA. The script correctly submits the CAPTCHA request but frequently receives the ERROR_CAPTCHA_UNSOLVABLE response from 2Captcha. I don't want to use selenium

    When I'm using a paid captcha solving service that means it should solve the captcha that I can't do without it.

    Here the code



    import requests

    import time



    API_KEY = "API_KEY"

    SITE_URL = "https://top.gg/bot/646937666251915264/vote"

    TURNSTILE_SITE_KEY = "0x4AAAAAAADnPIDR0Trrn1WwJw"

    MAX_RETRIES = 3



    def advanced_print(level, message):

    levels = {

    "INFO": "\033[94m[INFO]\033[0m",

    "ERROR": "\033[91m[ERROR]\033[0m",

    "SUCCESS": "\033[92m[SUCCESS]\033[0m",

    "DEBUG": "\033[93m[DEBUG]\033[0m"

    }

    print(f"{levels.get(level, '[LOG]')} {message}")



    def solve_turnstile(retries=0):

    try:

    advanced_print("INFO", "Submitting Turnstile CAPTCHA solution request to 2Captcha...")

    captcha_url = "http://2captcha.com/in.php"

    params = {

    "key": API_KEY,

    "method": "turnstile",

    "sitekey": TURNSTILE_SITE_KEY,

    "pageurl": SITE_URL

    }

    response = requests.post(captcha_url, params=params)

    if response.status_code != 200:

    advanced_print("ERROR", f"Failed to send CAPTCHA request. Status Code: {response.status_code}")

    return None

    if "OK|" in response.text:

    captcha_id = response.text.split('|')[1]

    advanced_print("INFO", f"Turnstile request submitted. ID: {captcha_id}")

    else:

    advanced_print("ERROR", f"Invalid CAPTCHA request response: {response.text}")

    return None



    fetch_url = f"http://2captcha.com/res.php?key={API_KEY}&action=get&id={captcha_id}"

    advanced_print("INFO", "Waiting for Turnstile solution...")

    while True:

    result = requests.get(fetch_url)

    if 'CAPCHA_NOT_READY' in result.text:

    time.sleep(5)

    elif "OK|" in result.text:

    captcha_solution = result.text.split('|')[1]

    advanced_print("SUCCESS", f"Turnstile CAPTCHA solved! Solution: {captcha_solution}")

    return captcha_solution

    elif "ERROR_CAPTCHA_UNSOLVABLE" in result.text:

    if retries < MAX_RETRIES:

    retries += 1

    advanced_print("ERROR", f"CAPTCHA unsolvable, retrying... Attempt {retries}/{MAX_RETRIES}")

    time.sleep(10)

    return solve_turnstile(retries)

    else:

    advanced_print("ERROR", "Reached max retries. CAPTCHA remains unsolvable.")

    return None

    else:

    advanced_print("ERROR", f"Failed to fetch CAPTCHA solution: {result.text}")

    return None

    except Exception as e:

    advanced_print("ERROR", f"Exception occurred during CAPTCHA solving: {str(e)}")

    return None



    def main():

    captcha_solution = solve_turnstile()

    if captcha_solution:

    advanced_print("SUCCESS", "CAPTCHA Solved successfully!")

    else:

    advanced_print("ERROR", "Turnstile CAPTCHA solution failed.")



    if __name__ == "__main__":

    main
    ()




    [INFO] Submitting Turnstile CAPTCHA solution request to 2Captcha...

    [INFO] Turnstile request submitted. ID: 77384590070

    [INFO] Waiting for Turnstile solution...

    [ERROR] Failed to fetch CAPTCHA solution: ERROR_CAPTCHA_UNSOLVABLE

    [ERROR] Turnstile CAPTCHA solution faile





    I have tried to check the api key, site key and tried to increase the delay of of it, I collected too much info which I got online but there no use. It didn't solve

    Continue reading...

Compartilhe esta Página