Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. s = requests.Session()
  2.  
  3. # GET
  4.  
  5. url = _build_sc_url('/profile/signin', secure=True)
  6. r = s.get(url)
  7. soup = BeautifulSoup(r.text)
  8. selector = '#formLogin input[name=__RequestVerificationToken]'
  9. verif_token = soup.select(selector)[0].attrs['value']
  10.  
  11. # POST
  12.  
  13. headers = {
  14.     'X-Requested-With': 'XMLHttpRequest',
  15.     'Content-Type': 'application/json', # remove when using json=...
  16. }
  17. payload = {
  18.     '__RequestVerificationToken': verif_token,
  19.     'login': 'rootri',
  20.     'password': 'dM20kzqhv5',
  21.     'rememberme': True,
  22. }
  23. url = _build_sc_url('/profile/signincompact', secure=True)
  24. # r = s.post(url, headers=headers, json=payload, allow_redirects=False)
  25. r = s.post(url, headers=headers, data=json.dumps(payload),
  26.            allow_redirects=False)
  27.  
  28. if not r.json()['Status']:
  29.     raise LoginFailureError(r.json()['ErrorText'])
  30.  
  31. self._sc_bot.sc_cookies = r.cookies
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement