python - fail to login to website with request -
at first here code:
import requests payload = {'name':'loginname', 'password': 'loginpassword'} requests.post('http://myurl/auth',data=payload,verify=false) rl = requests.get('http://myurl/dashboard',verify=false) print(rl.text)
my problem:
i status code 200 means login successfull. when try visit protected page http://myurl/dashboard output doesn't fit. shows me first page login , don't why.
i know there many questions studied every answer , docs dont it.
any nice. drives me cracy. in advance!
you need use session
object have requests
maintain track of cookies, such login cookie set after requests.post
login action. quoting the[first example there:
s = requests.session() s.get('http://httpbin.org/cookies/set/sessioncookie/123456789') r = s.get('http://httpbin.org/cookies') print(r.text) # '{"cookies": {"sessioncookie": "123456789"}}'
so in case:
import requests payload = {'name': 'loginname', 'password': 'loginpassword'} s = requests.session() r1 = s.post('http://myurl/auth', data=payload, verify=false) if r1.status_code == 200: # not necessary if sure login r2 = s.get('http://myurl/dashboard', verify=false)
Comments
Post a Comment