Example Implementations

from tls_client import Session
from requests import get, post
from bs4 import BeautifulSoup

if __name__ == "__main__":
    API_KEY = "TAKION_API_XXX" # Fill it with your api key
    MAIL = "email" # Your TM SG Mail
    PASSWORD = "pw" # Your TM SG Password

    session = Session("chrome_112")
    headers = {
        'Host': 'ticketmaster.sg',
        'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-user': '?1',
        'sec-fetch-dest': 'document',
        'referer': 'https://ticketmaster.sg/',
        'accept-language': 'en-GB,en;q=0.9',
    }

    # ------------------------- Generate reese84 ------------------------- #
    response = session.get("https://epsf.ticketmaster.sg/eps-d", headers={
        "accept": "application/json; charset=utf-8",
        "accept-language": "en-GB,en;q=0.9",
        "content-type": "text/plain; charset=utf-8",
        "origin": "null",
        "priority": "u=1, i",
        "sec-ch-ua": '"Chromium";v="125", "Google Chrome";v="125", "Not-A.Brand";v="99"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"macOS\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "cross-site",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
    })

    challenge_payload = post(
        "https://incapsula.takionapi.tech/reese84", 
        json={
            "script": response.text
        },
        headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
            "x-api-key": API_KEY
        }
    ).json()['payload']

    response = session.post(
        "https://epsf.ticketmaster.sg/eps-d", 
        headers={
            "accept": "application/json; charset=utf-8",
            "accept-language": "en-GB,en;q=0.9",
            "content-type": "text/plain; charset=utf-8",
            "origin": "null",
            "priority": "u=1, i",
            "sec-ch-ua": '"Chromium";v="125", "Google Chrome";v="125", "Not-A.Brand";v="99"',
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"macOS\"",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "cross-site",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
        }, 
        data=challenge_payload,
        params={"d":"www.ticketmaster.sg"}
    )
    response = response.json()
    
    # Set cookie
    session.cookies.set("reese84", response['token'])

    print("Starting...")
    
    # ------------------------- Load CSRF Token  ------------------------- #
    response = session.get('https://ticketmaster.sg/login', headers=headers)

    if (redirect := response.headers.get("Location")):
        response = session.get(redirect, headers=headers)

    headers = {
        'Host': 'main.login.ticketmaster.sg',
        'cache-control': 'max-age=0',
        'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'upgrade-insecure-requests': '1',
        'origin': 'https://main.login.ticketmaster.sg',
        'content-type': 'application/x-www-form-urlencoded',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-user': '?1',
        'sec-fetch-dest': 'document',
        'referer': 'https://main.login.ticketmaster.sg/login?client_id=6vdm5j83n4tc6i0ul4nm9ms6dm&redirect_uri=https%3A%2F%2Fticketmaster.sg%2Flogin&response_type=code&scope=phone+email+openid+aws.cognito.signin.user.admin',
        'accept-language': 'en-GB,en;q=0.9',
    }

    # ------------------------- Generate cognito ------------------------- #
    response = get(
        "https://cognito.takionapi.tech/generate",
        params={
            "api_key": API_KEY,
            "website": "www.ticketmaster.sg",
            "username": MAIL
        },
        headers={
            "User-Agent": headers["user-agent"],
            "sec-ch-ua": headers["sec-ch-ua"]
        }
    ).json()["result"]

    # ------------------------- Login into acc.  ------------------------- #
    response = session.post(
        'https://main.login.ticketmaster.sg/login', 
        params={
            'client_id': '6vdm5j83n4tc6i0ul4nm9ms6dm',
            'redirect_uri': 'https://ticketmaster.sg/login',
            'response_type': 'code',
            'scope': 'phone email openid aws.cognito.signin.user.admin',
        },  
        headers=headers, 
        data={
            '_csrf': session.cookies.get_dict()["XSRF-TOKEN"],
            'username': MAIL,
            'password': PASSWORD,
            'cognitoAsfData': response,
            'signInSubmitButton': 'Sign in',
        }
    )
    if (redirect := response.headers.get("Location")):
        response = session.get(redirect, headers=headers)
    if (redirect := response.headers.get("Location")):
        response = session.get(redirect, headers=headers)
    
    soup = BeautifulSoup(response.text, "html.parser")
    if not (account_data := soup.find("div", {"id": "accountFunc"})):
        print(soup.find("p", {"id": "loginErrorMessage"}).text)
        exit(0)

    print("Logged in as " + account_data.find("div").text)

Last updated