Here's the cURL , copied directly from the dev tools:
curl "https://*.php" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Content-Type: application/x-www-form-urlencoded" -H "Origin: https://moodle.upm.es" -H "DNT: 1" -H "Connection: keep-alive" -H "Referer: https://moodle.upm.es/titulaciones/oficiales/login/auth_index.php" -H "Cookie: **********" -H "Upgrade-Insecure-Requests: 1" --data-raw "password=***********"%"3D"%"3D&username=**********&logintoken=***********"
The reponse is a 303 code
When I try to do the same in Python:
mainsession = requests.post('https://*.php', headers=header, cookies=cookies, data=data)
It returns a 200 code and the response is an error page.
I've copied correctly all the headers and the other Post requests of my code work well so I don't know what I'm doing wrong.
You should add -L --location flag to your curl command to follow the redirect: