Saturday, 5 August 2023

Login with post request and xsrf token but getting a 419

I am trying to login to slicethepie.com using pythons requests library.

From my understanding, I am getting a 419 because I am not passing a csrf token. The only similar token I see in Chromes network tab is an XSRF-TOKEN. Do I need to pass that instead? Why is my code returning a 419?

You can currently see I am passing the XSRF token in the cookie but no luck.

import requests

link = "https://www.slicethepie.com/login"
response = requests.get(link)  # no XSRF token in here

payload = { "email": "private", "password": "private", "_token": "private", "validation": "token", location[latitude]: None, location[longitude]: None}

headers = {
    "Cookie": "XSRF-TOKEN=...tokenInImage...slicethepie_session=...tokenInImage...",
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate, br",
    "Connection": "keep-alive",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
    "Referer": "https://www.slicethepie.com/login",
    "Origin": "https://www.slicethepie.com",
}

with requests.Session() as s:
    p = s.post(
        "https://www.slicethepie.com/login",
        headers=headers,
        json=payload,
    )
    print(p) # returns 419. Page Expired

enter image description here

Form Data in Payload

_token: private
_token: private
validation: token
location[latitude]: None
location[longitude]: None
email: private
password: private


from Login with post request and xsrf token but getting a 419

No comments:

Post a Comment