Answer the question
In order to leave comments, you need to log in
How to log in to a site with CSRF protection?
there is a need to parse the site, all information on it is available only after authorization, there are problems with authorization.
the site is most likely on django, when sending a post request to the server, the login, password, "remember me" flag and csrf tokens (one in the cookie, the other from the page body) go away, the problem is that all my attempts return 500
code example:
import requests,re
session = requests.Session()
r1 = requests.get('https://report.xxx.ru/user/security/login')
csrftoken = re.findall(r"[^\"\>\{\}\\]{86}==", r1.text) #вычленяем csrftoken из тела страницы
print(r1.cookies)
data={'login-form[username]': 'login', 'login-form[password]': 'password', 'login-form[rememberMe]': '0', '_csrf': csrftoken[1]}
r2 = session.post("https://report.xxx.ru/user/security/login", params=data)
print(data)
print(r2.status_code)
print(r2.text)
r = session.get('https://report.xxx.ru/report/report/view?id=1')
Answer the question
In order to leave comments, you need to log in
the problem was that it was necessary to pass the parameters of the authorization form and csrf tokens using data and not params
r2 = session.post("https://report.xxx.ru/user/security/login", data=data)
Add allow_redirects=True to requests
You can also add verify=False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question