authentication - python requests with redirection -


trying authenticate on http://72.ru site, noticed there redirect https://loginka.ru/auth/. found there 302 post plain credentials in data form. copying headers chrome can reproduce in curl, still can't reach in requests module.

warning: page full of russian letters, registration in box north-east

with requests.session() s:     s.auth = ('email', 'passwd')      s.post('http://72.ru/passport/login.php')     p = s.get('http://72.ru/job/favorite/vacancy/')      # print true if logged     print('some title favorite page, if logged' in p.text) 

why can't authenticate, doing wrong?

there simpler way perform login website.

import requests  headers = {     "user-agent":         "mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/41.0.2272.101 safari/537.36", }  s = requests.session() s.headers.update(headers)  # there dedicated login page, url of login button on site, can open directly.  # requests automatically take care of rediects s.get('https://loginka.ru/auth/?url=http%3a%2f%2f72.ru')  # generate post data data = {     'url': 'http://72.ru',     'email': username,     'password': password }  # perform post request r = s.post('https://loginka.ru/auth/?url=http%3a%2f%2f72.ru', data=data)  # there post request on site uses token redirect url token = r.url[r.url.index('token=')+6:] url = 'http://72.ru/put_token_to_user/?token=' + token + '&dummy_put_token_to_user=yes' headers2 = {'x-requested-with': 'xmlhttprequest', 'referer': r.url} r = s.get(url, headers=headers2)  r = s.get('http://72.ru/passport/mypage.php') print r.url print r.status_code open('abc.txt', 'wb') f:     f.write(r.content) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -