W
W
wolron2020-05-05 08:21:36
Python
wolron, 2020-05-05 08:21:36

Authorization via Post request for a form using requests?

What Python code will be able to log in to the site after entering its username and password to get the closed page https://employee-sales.bsh-group.ru/myaccount/staf...

import requests
from bs4 import BeautifulSoup

HEADERS = {......}

dat = {  
  'loginUrl' : '/sys/login',
  'errorPageUrl' : 'https://employee-sales.bsh-group.ru/myaccount/staff-login',
  'successPageUrl' : 	'https://employee-sales.bsh-group.ru/myaccount/staff-login',
  'username' : 'def', 
  'password' : 'def', 
  '_csrf'	 : 'def'
  }

login = input('Login: ')
passwd = input('Password: ')

dat['username']  = login 
dat['password'] = passwd 

s = requests.Session()
ppp = s.post("https://employee-sales.bsh-group.ru/sys/login" ,headers=HEADERS, data=dat)
print(ppp.status_code)


When logging in, it should display 302? 200 is displayed.
If I enter through the browser, then the entrance is normal.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey_Dolg, 2020-05-05
@Andrey_Dolg

Check if the header is correct. Perhaps there is something missing in the cookies, try first to always go to the authorization page (the page with the fields for entering your login and password) and then send a request within the same session. It's also rather strange to see _csrf in payload and not in cookies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question