I am trying to login to https://admin.raptor.software
using a POST request from python, but am unable to.
I am using following code snippet:
import requests_html
session = requests_html.HTMLSession()
r = session.get('https://admin.raptor.software')
csrf = r.html.xpath('/html/head/meta[4]')[0].attrs['content']
data = {
'client_id': '2',
'client_secret': csrf,
'grant_type': 'password',
'password': 'MYPASSWORD',
'username': 'MYEMAIL'
}
session.post('https://admin.raptor.software/api/login', data = data)
I need to post csrf
with it so I use the requests_html
library to get it.
After a successful login, I expect to print the dashboard HTML with the following code, but it posts the login page HTML above:
r = session.get('https://admin.raptor.software/dashboard')
print(r.text)
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0">
<meta name="csrf-token" content="eFC7HQfM9NJdi8u1nxQjDubUNjLLjVrmVmM1T4mD">
<link href="/css/app.css?id=39d4a60bbe483994f0ec" rel="stylesheet">
<title>Admin</title>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<!-- Styles -->
<link href="https://admin.raptor.software/css/app.css" rel="stylesheet">
<link href="https://admin.raptor.software/css/modules.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>
<body>
<div id="app">
</div>
<script src="/js/app.js?id=3f08b75b370e0e33ea8b"></script>
<script src="/js/modules.js?id=65903b83a0bc6fc9f233"></script>
</body>
</html>
try using
import requests
session = requests.Session()
r = session.post("https://website.com/example/login", data={
"username": "username here",
"password": "password here"
})
r = session.get("https://website.com/example/dashboard")
print(r.text)
What this script does, it does everything as your script, but instead I use requests and not requests_html
I tried My script with Google and other plataforms and it worked.
Hope it's usefull!