I keep failing to log in with Python requests, so why?

Asked 1 years ago, Updated 1 years ago, 87 views

I tried to log in by coding as below, but I keep failing.ㅠ<

When I checked the form transfer data history with the developer tool, there were only three: returnUrl, memberId, and passwd. At first, I tried to make log data into a dictionary, but I failed I tried to make a header just in case, but failed...

The _csrf value is not required and is not on the html code.

Where is the problem?

(verify=False) fails...The return value is 200, but you cannot log in... Can you predict what the reason is?

import requests
url = "https://www.happycampus.com/site/login/" #Request on response header url

  log = {
    "memberId" : "ID",
    "passwd": "Password",
    "returnUrl" : "/"
}

header = {
    "Referer": "https://www.happycampus.com/",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
}

with requests.Session() as s:
    login = s.post(url, headers=header, data=log)
    print(login.text.find('logout') #To verify that login is successful

requests

2022-09-22 14:19

1 Answers

There is no problem with the source.

When I tested it, After logging in

We accept the following results.

That is, self after authentication.location.replace ('https://www.happycampus.com/'); invoking index page.

HTTP/1.1 200 OK
Date: Sat, 30 Mar 2019 19:25:21 GMT
Server: Apache
Expires: 0
Cache-Control: pre-check=0, post-check=0, max-age=0
Pragma: no-cache
Set-Cookie: HAPPYCAMPUS_SESSID=tvrhv9qjulpq0ar2h9vkc1quk7; path=/; domain=.happycampus.com
Last-Modified: Sat, 30 Mar 2019 19:25:21 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 298

<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--//


self.location.replace('https://www.happycampus.com/');

//-->
</script>
</body>
</html>

Please change the source on the question and test it as below.

with requests.Session() as s:
    login = s.post(url, headers=header, data=log)
    index = s.get('https://www.happycampus.com/')
    print(index.text.find('logout') #To verify that login is successful


2022-09-22 14:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.