Authorization requests post python get empty data?

Trying to log in via requests.post, but the authorization does not pass and get a blank data
import requests
headers = {
"User-Agent":
 "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36",
 'Content-Type': 'text/html; charset=UTF-8'}
s = requests.Session()
s.headers.update(headers)
s.get('https://edu.tatar.ru')
s = s.post('https://edu.tatar.ru/logon', data={'main_login': 'login', 'main_password':'pass'})
print(s.text)

s.nothing in the text itself contains no
April 19th 20 at 12:08
2 answers
April 19th 20 at 12:10
Solution
Try this:
s = requests.Session()
s.headers.update(headers)
s.post('https://edu.tatar.ru/logon', data={'main_login': 'login', 'main_password':'pass'})
response = s.get('https://edu.tatar.ru')
print(response.text)

Perhaps post nothing returns, and only gets cookies.
I don't have a login to this site, so I used a random username and password. In response, we received only 'Response [200]'(which is a bit strange), and also an empty response.
When using valid login/pass the same get status 200 and an empty response, when viewed through chrome first is a 302 and then 200, but if you look response.history there are only 200, the response.cookie too - tomas.Sanfo commented on April 19th 20 at 12:13
@kavon12, tell me, and how should cookies be stored in the event post ?
I thought through the maintain session, something like that:

import requests

with requests.Session() as session:
 auth = dict(username='login', password='pass') # Data dictionary that are sent in the POST
 r = session.get('https://edu.tatar.ru/logon', timeout=5) # Get the page with the login form
 r.encoding = 'utf-8'
 session.post('https://edu.tatar.ru/logon', auth) # data Sent in the POST recorded our session cookies
 r = session.get('https://edu.tatar.ru', timeout=5)
 print(r.text)
- leilani2 commented on April 19th 20 at 12:16
@tomas.Sanfo, Try to POST the request to send headers(important I'm stressed)
5e97043dafedc585214322.png - kavon12 commented on April 19th 20 at 12:19
@leilani2, I faced the library requests nearly every day, but the sessions rarely worked. - kavon12 commented on April 19th 20 at 12:22
@leilani2, I tried using your code with and substituted with a valid log/pass authorization fails and r.the cookie itself does not contain, a feeling that after the code 302 and the transition to the 200 response itself is trimmed - tomas.Sanfo commented on April 19th 20 at 12:25
@leilani2, I have seen one site, which has not been able to log in until you gave the title 'Upgrade-Insecure-Requests: 1' and another title. - kavon12 commented on April 19th 20 at 12:28
@kavon12, tried, tripped in the headers, well the answer is 200 and an empty response - tomas.Sanfo commented on April 19th 20 at 12:31
@tomas.Sanfo, I Can still offer to try the program Postman - kavon12 commented on April 19th 20 at 12:34
@tomas.Sanfo, more if you take a cookie from chrome it is working and with requests they can't - tomas.Sanfo commented on April 19th 20 at 12:37
@tomas.Sanfo, the last attempt :)

with requests.Session() as session:
 r = session.get('https://edu.tatar.ru/logon', timeout=5) # Get the page with the login form
 r.encoding = 'utf-8'
 response = session.post(
url='https://edu.tatar.ru/logon/',
 # pass the authorization parameters and post request
data={
 'main_login': 'login',
 'main_password': 'password',
},
 headers = {
 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0",
 'Content-type': 'application/x-www-form-urlencoded',
 'Accept': 'text/html',
 'Referer': 'https://edu.tatar.ru/logon',
 'Upgrade-Insecure-Requests': '1'
},
 ) # Send the data in POST session recorded our cookies
 r = session.get('https://edu.tatar.ru/logon', timeout=5)
 print(r.text)
- leilani2 commented on April 19th 20 at 12:40
@leilani2, So You have succeeded or not? I can't see accounts on the site. - kavon12 commented on April 19th 20 at 12:43
@kavon12, I don't have accounts, the tester works the author of the question :) - leilani2 commented on April 19th 20 at 12:46
@leilani2have Confused You with the author of the question) - kavon12 commented on April 19th 20 at 12:49
well, sho there, have overcome? - arlo79 commented on April 19th 20 at 12:52
@arlo79, very interesting. - kavon12 commented on April 19th 20 at 12:55
@kavon12, vanquished, but it is not clear how, suddenly from nothing started to response for post request data and cookies - tomas.Sanfo commented on April 19th 20 at 12:58
Thank you all! - tomas.Sanfo commented on April 19th 20 at 13:01
April 19th 20 at 12:12
mean, here I tell you

the first step for any site to teach, right?

the article read, article make, right?

Find more questions by tags Python