Search code examples
pythonhttppython-3.xhttp-request

Authentication using API Request


I'm currently writing a short script using the Request API and I need to access my e-mail box in order to retrieve some information.

So I wrote this code in order to authenticate:

#! /usr/bin/python3

import requests

payload = {'horde_user': '',
           'horde_pass': '',
           'login_post': '1'}


r = requests.post('http://webmail.technion.ac.il/login.php', data=payload)

print(r.status_code)
print(r.text)

Obviously I replaced horde_user by my username and horde_pass by my password in the payload dictionary.

But the output is the source code of the initial page, while I expected it to be the content of my mail box.

And the status code is 200 while it is supposed to be 302. Could somebody explain to me what I'm doing wrong.

Thanks a lot for helping!


Solution

  • Try requesting the page first and then pulling out the session ids from that first request to be used in the login attempt. I bet it is failing because you're sending old session ids and the website is rejecting them and sending you back to the login page with a new session id. The session ids would be Horde and horde_secret_key in the cookies.