2014-04-13 65 views
0

所以我想登录并导航到使用Python和请求的页面。我非常肯定我已经登录,但是一旦我尝试导航到页面时,从该页面打印的HTML表明您必须登录才能看到此页面。保持登录W/Python请求

这里是我的代码登录。

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 

任何帮助或想法将是巨大的!

+0

你需要以某种方式处理饼干。 –

回答

0

这里登录,获得最终的cookie,然后使用他们做出另一个请求的例子:

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)