Sctaping web with Cloudflare Turnstile (Token)
19:17 11 Aug 2026

I’m trying to query the “Verifica si estás inscrito en el Registro Nacional de Grados y Títulos” service at https://enlinea.sunedu.gob.pe/.

The web flow requires a document ID (for testing, I’m using 08117145). The request appears to require a security token generated by an invisible Cloudflare/browser verification step.

I tried cloudscraper and cfscrape, but:

cloudscraper.get_tokens("https://constanciasweb.sunedu.gob.pe")

returns:

CloudflareIUAMError:
Unable to find Cloudflare cookies. Does the site actually have
Cloudflare IUAM (I'm Under Attack Mode) enabled?

My current code successfully obtains the bearer token, but the protected request fails because I do not know how the Token field is obtained:

import requests

API = "https://constanciasapi.sunedu.gob.pe/api"
WEB = "https://constanciasweb.sunedu.gob.pe"

session = requests.Session()
session.headers.update({
    "Accept": "application/json, text/plain, */*",
})

# 1. Obtain bearer token
auth = session.post(
    f"{API}/Token/generar-token",
    json={"subject": "constancias-app"},
    timeout=20,
)
auth.raise_for_status()

auth_data = auth.json()
if not auth_data.get("bSuccess") or not auth_data.get("oData"):
    raise RuntimeError(auth_data)

bearer = auth_data["oData"]

# 2. Security token from the browser verification flow
payload = {
    "Token": "",
    "IpAddress": "",
    "NumeroDocumento": "08117145",
    "ApellidosNombres": "",
}

# 3. Query degree registry
response = session.post(
    f"{API}/VerificaGrados/obtener-grados-nac-ext-ct-verifica",
    json=payload,
    headers={
        "Authorization": f"Bearer {bearer}",
        "Origin": WEB,
        "Referer": f"{WEB}/",
    },
    timeout=20,
)

print("HTTP:", response.status_code)
print(response.json())

Could someone explain where the Token value is generated during the normal browser flow, whether it is tied to the browser session, IP address, or cookies, and how it should be handled in an authorized automated test? Ideally, I’m looking for an approach that does not depend on browser automation tools such as Selenium, since performance matters for my scraping use case.

python web-scraping request cloudflare cloudflare-turnstile