NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

AWS WAF and other CAPTCHAs

How to solve the AWS WAF CAPTCHA in Python

When a site behind AWS WAF answers your script with a puzzle page instead of content, one API task returns the aws-waf-token cookie that lets the session continue. It costs $1.40 per 1,000 solved tasks and usually arrives under 3 seconds.

How the AWS WAF check reaches your script

Your script sees a short HTML page and an unusual status code instead of the data it asked for. AWS WAF lets site owners attach a CAPTCHA action to a rule, and when a request matches, the firewall replies with a puzzle page rather than forwarding the request to the application. At the time of writing that page arrives with HTTP status 405, while the silent Challenge action uses 202. Both pages exist to issue one thing: a cookie named aws-waf-token.

Once a browser holds a valid aws-waf-token, the firewall lets its requests through until the token's immunity period ends, which the site owner configures (often a few minutes). That is good news for a Python client: you do not need a browser or a puzzle renderer, you only need a valid cookie in your requests.Session. The AWS WAF CAPTCHA glossary entry explains the firewall side in more depth.

What you need

  • Python 3.10 or newer and the requests package.
  • Your GateSolver API key, kept in an environment variable rather than in the source file.
  • The URL that returns the puzzle page. Use the exact address your script was requesting, including the path, not just the home page.

The task type is AntiAwsWafTaskProxyLess. Only websiteURL is required. Three optional fields, awsKey, awsIv and awsContext, carry values printed in the puzzle page itself; sending them lets the task work from the very challenge your session received. A separate guide shows how to find the AWS WAF parameters by hand when a regular expression is not enough.

Recognise the puzzle page in code

Check the status code first and the body second. A 405 alone could be an ordinary "method not allowed" from the application, so confirm the page also contains the gokuProps object that the AWS integration script reads. The helper below returns the three values when they are present and None when the response is a normal page.

import json
import re

GOKU = re.compile(r"gokuProps\s*=\s*(\{.*?\})", re.S)

def waf_values(resp) -> dict | None:
    if resp.status_code not in (202, 405):
        return None
    found = GOKU.search(resp.text)
    if not found:
        return None
    try:
        props = json.loads(found.group(1))
    except ValueError:
        return {}
    return {"awsKey": props.get("key"), "awsIv": props.get("iv"),
            "awsContext": props.get("context")}

An empty dictionary means "this is the WAF page, but I could not parse the values". The task still runs without them, so the caller treats an empty result as a valid signal and only None as "no challenge here".

Create the task and wait for the cookie

The solver function posts the task, then polls /getTaskResult every three seconds. The answer for this type is a single string in solution.cookie; there is no token field and no user agent to copy, which keeps the follow-up simple.

import os
import time
import requests

WAF_API = "https://gatesolver.com"
WAF_KEY = os.environ.get("GATESOLVER_KEY", "YOUR_API_KEY")

def call_api(method: str, **fields) -> dict:
    data = requests.post(f"{WAF_API}/{method}", timeout=30,
                         json={"clientKey": WAF_KEY, **fields}).json()
    if data.get("errorId"):
        raise RuntimeError(data.get("errorCode", "unknown error"))
    return data

def aws_waf_cookie(page_url: str, extra: dict) -> str:
    task = {"type": "AntiAwsWafTaskProxyLess", "websiteURL": page_url}
    task.update({k: v for k, v in extra.items() if v})
    job_ref = call_api("createTask", task=task).get("taskId")
    for _ in range(42):
        time.sleep(3)
        outcome = call_api("getTaskResult", taskId=job_ref)
        if outcome["status"] == "ready":
            return outcome["solution"]["cookie"]
        if outcome["status"] == "failed":
            break
    raise RuntimeError(f"AWS WAF task {job_ref} ended without a cookie")

The dictionary comprehension drops empty values so the task never carries "awsIv": null. Forty-two rounds of three seconds cover the 120 seconds after which an unsolved task is marked failed and left unbilled.

Store the cookie and repeat the request

Put the value into the session's cookie jar under the name aws-waf-token, scoped to the host you are visiting, and send the original request again. Every later request in the same session carries the cookie automatically.

from urllib.parse import urlparse

def fetch_through_waf(sess: requests.Session, url: str) -> requests.Response:
    first = sess.get(url, timeout=25)
    values = waf_values(first)
    if values is None:
        return first
    token = aws_waf_cookie(url, values)
    host = urlparse(url).hostname
    sess.cookies.set("aws-waf-token", token, domain=host, path="/")
    second = sess.get(url, timeout=25)
    if waf_values(second) is not None:
        raise RuntimeError("the WAF page came back; try the proxy task type")
    return second

with requests.Session() as web:
    web.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) price-check/1.4"
    page = fetch_through_waf(web, "https://example.com/catalog?page=2")
    print(page.status_code, len(page.content))

Keep the session alive for the rest of the job. Solving once and reusing the cookie for every page until it expires is both faster and cheaper than solving per request.

When the cookie is refused

If the second request gets the puzzle page again, the usual reason is that the site ties the token to the address that earned it. Switch to AntiAwsWafTask and add a proxy field in the form http://user:pass@host:port, using the same proxy your session sends traffic through (web.proxies = {"https": proxy_url}). Our note on proxyless or proxy tasks covers when each one fits.

Other causes are quick to rule out:

  • Wrong URL in the task. Send the URL that actually returned the 405, not the site's front page.
  • Stale context. The context value changes on each load of the puzzle page, so read it from the response you are answering, not from one saved earlier.
  • Expired token. After the immunity period the 405 returns. Detect it with the same helper and solve again rather than treating it as an error.

Errors worth handling

ERROR_INVALID_TASK_DATA names the field it did not like, usually an empty websiteURL. ERROR_ZERO_BALANCE means the balance ran out; top up and continue, because the balance never expires. ERROR_CAPTCHA_UNSOLVABLE and ERROR_SERVICE_UNAVAILABLE cost nothing and deserve one or two retries after a short pause. ERROR_RATE_LIMIT means more than 600 API requests in a minute on your key, which a three second poll interval avoids unless you run hundreds of solves in parallel.

Several sites in one job

If one script visits many domains, give each domain its own Session and its own cookie. An aws-waf-token earned on one site means nothing to another, and keeping the sessions apart makes it obvious in logs which host needed a fresh solve. A thread pool works well here: each worker owns one session, solves at most once per immunity period, and the API happily runs many tasks at the same time. Count your polls, though. Ten workers polling every three seconds use about 200 requests a minute, comfortably inside the 600 per minute allowed for one key.

Price trackers, catalog monitors and QA suites are the natural home for this code. Keep request rates polite: one cookie serves many pages, so there is rarely a reason to hammer a site.

For other languages, the same flow is written for Node.js with Playwright and PHP with cURL, and the AWS WAF solver page lists the current price.

Common questions

Does an AWS WAF task need a browser on my side?

No. The answer is a cookie value, so a requests.Session that stores it under aws-waf-token is all you need for plain HTTP pages.

Are awsKey, awsIv and awsContext required?

No, only websiteURL is required. Sending the three values read from the puzzle page ties the task to the challenge your session actually received.

How long can I reuse the aws-waf-token cookie?

Until the site's immunity period ends, which the site owner sets. When the 405 page appears again, solve a new task.

What does the 202 status mean on an AWS WAF site?

It usually marks the silent Challenge action. It also issues aws-waf-token, and the same task type returns a cookie for it.

Am I charged if the cookie does not work?

You are charged when a task is solved and returns a cookie. Failed, unsolvable and timed out tasks are free, so check the URL and proxy before retrying.

Keep reading