Question

Fixed, httplin2 can't handle more than one cookie, the patch can be found here: http://code.google.com/p/httplib2/issues/detail?id=146

I am coding a facebook login script to get my last notifications but I'm having a problem. I've changed from urllib to httplib2 because it seemed easier and faster to me. Using the urllib I was able to get the correct cookie and use it when ever I needed to retrieve the notifications, now I'm using the example from the httplib page:

user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN;

rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8' headers = {'User-Agent' : user_agent, 'Content-type': 'application/x-www-form-urlencoded', 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8', 'Connection' : 'keep-alive', 'Accept-Encoding' : 'gzip, deflate', 'Referer' : 'http://m.facebook.com/' } data = {'email' : 'myusername', 'pass' : 'mypassword', 'post_form_id' : '', 'charset_test' : '', 'version': 1, 'ajax' : 1, 'pxr' : 1, 'gps' : 1, 'login' : 'Entrar'} response, content = h.request("http://www.facebook.com/login.php?m=m&refsrc=http://m.facebook.com/&refid=0", "POST", urllib.parse.urlencode(data), headers=headers)

And this is the header I'm getting:

{'status': '200', 'x-cnection': 'close', 'content-location':

'http://m.facebook.com/home.php?refsrc=http%3A%2F%2Fm.facebook.com%2F&refid=0&m_sess=***tAm60&_rdr', 'transfer-encoding': 'chunked', 'set-cookie': 'datr=******F-OQsTCnbw0Caa; expires=Fri, 06-Sep-2013 20:33:26 GMT; path=/; domain=.facebook.com; httponly', 'expires': 'Sat, 01 Jan 2000 00:00:00 GMT', 'x-fb-server': '10.62.188.41', 'content-length': '26702', '-content-encoding': 'gzip', 'pragma': 'no-cache', 'cache-control': 'private, no-cache, no-store, must-revalidate', 'date': 'Wed, 07 Sep 2011 20:33:27 GMT', 'p3p': 'CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"', 'content-type': 'text/html; charset=utf-8', 'x-frame-options': 'DENY'}

If I don't use the h.follow_all_redirects = True option, it doesn't redirect me to the home page, but the set cookies are on the first page before redirecting. The cookies I get are: set-cookie': 'datr=F*******F-OQsTCnbw0Caa; expires=Fri, 06-Sep-2013 20:33:26 GMT; path=/; domain=.facebook.com; httponly'

But those cookies aren't enough to get the session active. In the browser I'm getting a larger cookie:

datr=EzIL*********e-JFJL; lu=wgrr3q**********; locale=es_LA; L=2;

act=13*****; m_user=***%40gmail.com%3A526402587%3AN******%3A0%3Av_1%2Cajax_1%2Cwidth_1600%2Cpxr_1%2Cgps_1%3A13***1099; p=182; fl=1; W=13****99; reg_fb_ref=https%3A%2F%2Fwww.facebook.com%2Flogin.php%3Fm%3Dm%26refsrc%3Dhttp%253A%252F%252Fm.facebook.com%252F%26refid%3D0

What could be the problem?

Was it helpful?

Solution

Fixed, httplin2 can't handle more than one cookie, the patch can be found here: http://code.google.com/p/httplib2/issues/detail?id=146

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top