简体   繁体   English

Python 3 httplib2 cookie

[英]Python 3 httplib2 cookies

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 修复了,httplin2无法处理多个cookie,可以在此处找到该补丁: 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. 我正在编写一个facebook登录脚本来获取我的最后通知,但我遇到了问题。 I've changed from urllib to httplib2 because it seemed easier and faster to me. 我已经从urllib更改为httplib2,因为它对我来说似乎更容易,更快。 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: 使用urllib我能够获得正确的cookie并在需要检索通知时使用它,现在我正在使用httplib页面中的示例:

 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) 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' , '连接': '保持活跃', '接受编码': 'gzip的,放气', '引用站点': 'http://m.facebook.com/'} data = {'email':'myusername','pass':'mypassword','post_form_id':'','charset_test':'','version': 1,'ajax':1,'pxr':1,'gps':1,'登录':'Entrar'}响应,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; '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; 到期日= 2013年9月6日星期五20:33:26 GMT; path=/; 路径= /; domain=.facebook.com; 域= .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; httponly','expires':'星期六,2000年1月1日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没有P3P政策。在这里了解原因: http//fb.me/p3p ”','content-type':'text / html; charset=utf-8', 'x-frame-options': 'DENY'} 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. 如果我不使用h.follow_all_redirects = True选项,它不会将我重定向到主页,但设置的cookie在重定向之前位于第一页。 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' 我得到的cookies是: set-cookie': 'datr=F*******F-OQsTCnbw0Caa; expires=Fri, 06-Sep-2013 20:33:26 GMT; path=/; domain=.facebook.com; httponly' 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. 但这些cookie不足以让会话活跃起来。 In the browser I'm getting a larger cookie: 在浏览器中我得到一个更大的cookie:

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

act=13* * ** * ; act = 13 * * ** * ; m_user= * ** %40gmail.com%3A526402587%3AN* * **** %3A0%3Av_1%2Cajax_1%2Cwidth_1600%2Cpxr_1%2Cgps_1%3A13* ** 1099; m_user = * ** %40gmail.com%3A526402587%3AN * * **** %3A0%3Av_1%2Cajax_1%2Cwidth_1600%2Cpxr_1%2Cgps_1%3A13 * ** 1099; p=182; P = 182; fl=1; FL = 1; W=13 *** *99; 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 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? 可能是什么问题呢?

修复了,httplin2无法处理多个cookie,可以在此处找到该补丁: http//code.google.com/p/httplib2/issues/detail? id = 146

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM