Linked Questions

Popular Questions

Use python requests to login to laravel app

Asked by At

I want to use python request to login to a Laravel app and get the content of the first page after login, I tried:

import requests
import re

URL = 'laravelapp.url'

session = requests.session()

front = session.get(URL)
csrf_token = re.findall(r'<input type="hidden" name="_token" value="(.*)"', front.text)[0]

print(csrf_token)
print(session.cookies['XSRF-TOKEN'])

payload = {
    'email': '[email protected]',
    'password': 'testtest',
    '_token': csrf_token,
}

r = requests.post(URL + '/login', data=payload)

print(r)

But this unfortunately returns only a 419 Error. So there seems to be anything wrong with csrf token? But I cant understand what is going wrong, the cookies should be managed by .sessions() and I extracted the csrf token from the login form and put it as param to the post data. So, what is missing?

Related Questions