0

这是 cURL ,直接从开发工具复制:

curl "https://moodle.upm.es/titulaciones/oficiales/login/index.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

当我尝试在 Python 中做同样的事情时:

    mainsession = requests.post('https://moodle.upm.es/titulaciones/oficiales/login/index.php', headers=header, cookies=cookies, data=data)

它返回一个 200 代码,响应是一个错误页面。

我已经正确复制了所有标题,并且我的代码的其他 Post 请求运行良好,所以我不知道我做错了什么。

4

1 回答 1

0

您应该在 curl 命令中添加 -L --location 标志以遵循重定向:

curl -L "https://moodle.upm.es/titulaciones/oficiales/login/index.php"
于 2021-03-08T20:46:09.377 回答