I am currently trying to login to my own web application via request. I have tried everything and every method out there but I am still getting the page expired error. My application is built with laravel and the login form is a basic post request with csrf token in it.Things I have tried so far:
-Using session and updating session token after first get request and then posting with that session
-Doing the same as above but without session
-Trying to get the view page first(It is a normal html page with login middleware) and since it will get back to me after rediraction, I will have that form and the token will be inside of it thanks to laravel.I did that and get the token from the hidden input field and tried to post with that but still didn’t work either
And also I have tried every combination of using those datas in data,cookie,header attributes
from bs4 import BeautifulSoup
import requests
url = 'http://localhost:8000/test'
r = requests.get(url)
form = BeautifulSoup(r.text,'html.parser').find('form')
loginURL = form['action']
token = form.find('input')['value']
print(token)
print(loginURL)
print("-------")
data = {
'email': 'admin@admin.com',
'password': 'admin',
'csrftoken': token
}
headers = {'X-CSRF-TOKEN':token}
login = requests.post(loginURL, data=data, headers=r.headers)
print(login)
And this was my last try and still didn’t work