1

So I am trying to log into and navigate to a page using python and requests. I'm pretty sure I am getting logged in, but once I try to navigate to a page the HTML I print from that page states you must be logged in to see this page.

Here is my code to log in.

payload = {

    'business_user_session[email]': 'some_email',
    'business_user_session[password]': 'some_pass'
    }


with session() as c:
    r = c.post('https://my.example.com/login', data=payload)
    r2 = c.get('https://my.example.com/transactions')
    #print r.headers
    print r2.text

Any help or ideas would be great!

1
  • You need to handle the cookies somehow. Commented Apr 13, 2014 at 12:28

1 Answer 1

3

Here's an example of logging in, getting the resultant cookies, then using them to make another request:

    login_request = requests.post(ROUTE_AUTHENTICATE,
                                  data=LOGIN_CREDS,
                                  headers={"Content-Type": "application/json"})
    self.assertEqual(login_request.status_code, 200)
    self.cookies = login_request.cookies

...

    thing_request = requests.get(url, cookies=self.cookies)
    self.assertTrue(thing_request.status_code, 200)

    things = json.loads(things.text)

Not the answer you're looking for? Browse other questions tagged or ask your own question.