Search code examples
pythonrequestsession-cookies

Making a http request using a session token to log in a website on python


Firstly, the objective is to make a http request every certain time, but there is a problem: the login screen.

In short, i tried to make a request to the link firefaucet.win/start with this code below

import requests    
requests.get('https://firefaucet.win/start')

This request returns to the login page, because to use this website you need to have a account.
Doing by the common way, making a POST request with the auth is out of question, because the login is followed by a captcha box. I figured out another way to log in, that is using my own session token, that i got on the cookies of my browser. But this is the point, I don't know how to log in using just the session token.


Solution

  • I read a lot on the requests lib docs and the answer is just make a request session object and make the request using the cookies kwarg, that is default to None. Just by reading that the session token is kept in a cookie named "session" on the browser, I achieved the objective just by putting the session token inside the "session" cookie like the code below:

    import requests
    obj = requests.Session()
    response = obj.request(
        'get', 
        'https://firefaucet.win/start',
        cookies={
            'session': 'session token here'
        }
    )
    print(response)