« Return to Thread: [CPyUG:41451] 关于urllib2中的Keep-Alive及请教好用的http客户端包

[CPyUG:41451] 关于urllib2中的Keep-Alive及请教好用的http客户端包

by hechu :: Rate this Message:

Reply to Author | View in Thread

各位好:

我用python写一个http协议的网站数据搜集程序,用到urllib2库,这个程序要用使用代理服务器,并且要用登录会话,所以用到了 ProxyHandler和CookieLib中的CookieJar。用了很长时间都没问题,感觉很方便。

昨天在升级增加功能的时候,发现有个地址可能需要Connection=Keep-Alive的连接,才能正常工作,否则会出现错误。我用Firefox 发送正常请求,并抓包,与我程序发送的请求做对比,区别就在Header的Keep-Alive=300,和Connection=Keep-Alive 这两句上。我尝试在urllib2的opener中增加header来实现,发现无论如何发出的请求都是connection=close。

搜索互联网,发现已经有人提出过这个问题,并指出urllib2硬编码,导致connection保持为close。

网上有人推荐用httplib2,我粗略看了一下文档,支持cookie和proxy,但是我还非常留恋urllib2中那些其它的handler,,,

我的问题如下:
1. urllib2的keep-alive问题有没有好的解决方法?
2. 有没有好用的http客户端?httplib2貌似是个方案;twisted的web/web2不知道如何;昨晚看了一下pycurl,好像也行,,,想 听听大家的意见。

谢谢!

--~--~---------~--~----~------------~-------~--~----~
'''邮件来自Groups "python-cn"--China Py User Group
详情: http://groups-beta.google.com/group/python-cn
发言: python-cn@...
退订: python-cn-unsubscribe@...
维基: http://wiki.woodpecker.org.cn/moin/CPUG
珠江事务: http://groups.google.com/group/zpug
东南事务: http://groups.google.com/group/cpug-eastchina
北京事务: http://groups.google.com/group/bpug
中国事务: http://groups.google.com/group/CPUG
同质列表: http://python.cn/mailman/listinfo/python-chinese
'''
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: [CPyUG:41451] 关于urllib2中的Keep-Alive及请教好用的http客户端包