【python 爬虫】使用代理的同时自定义opener报错

派僧_hellowoah 2015-11-09 12:23:14
[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

以上是错误信息

import urllib2
import cookielib

proxy_support = urllib2.ProxyHandler({'http':'xxxxProxy'})
opener0 = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener0)

# build request
url = 'http://passport.csdn.net/account/login' # cannot work on opener, but can work on urlopen
request = urllib2.Request(url)

cookie = cookielib.CookieJar()
chandler = urllib2.HTTPCookieProcessor(cookie)
print 'debug: ' , cookie, type(cookie),chandler, type(chandler)

opener = urllib2.build_opener(chandler)
urllib2.install_opener(opener)


try:
response = opener.open(request) # fail
except urllib2.URLError, e:
if hasattr(e, 'reason'):
print e.reason

for item in cookie: # read from response = urllib2.urlopen(request)
print 'name:', item.name
print 'value:', item.value


使用自定义opener打开内网并没有出现任何问题
使用urllib2.urlopen() 打开外网也没有问题
自定义opener打开外网就有问题,
how to solve 啊?求大神帮帮我这个入门小白吧
...全文
103 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,717

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧