urlopen error [errno 10060]的解决思路
当用多线程爬取某个网站的数据的时候,爬取一段时间后,总出现urlopen error [errno 10060]的错误,结果线程无端的被挂掉,一开始的解决思路是每次连接的时候换用不同的useragent,结果还是出现这种问题,在网上查了下,看到网上别人的经验,原来是 如果用多个线程爬去某个网站的数据,每次连接完的时候,需要sleep(1)一会,不然该网站服务端的防火墙会ban掉你的connect。so 按照这种解决方法,果然不再出现urlopen error [errno 10060]的异常了。
睡眠等待机制会减少urlopen error [errno 10060]出现的概率,但访问次数多了还是会出现
于是看了网上说法是连接时网络不稳定造成的,于是写了个多次尝试连接的函数
- def getUrl_multiTry(url):
- user_agent ='"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36"'
- headers = { 'User-Agent' : user_agent }
- maxTryNum=10
- for tries in range(maxTryNum):
- try:
- req = urllib2.Request(url, headers = headers)
- html=urllib2.urlopen(req).read()
- break
- except:
- if tries <(maxTryNum-1):
- continue
- else:
- logging.error("Has tried %d times to access url %s, all failed!",maxTryNum,url)
- break
- return html
经测验,可以搞定urlopen error [errno 10060]
urlopen error [errno 10060]的解决思路的更多相关文章
- [爬虫]爬虫时碰到的IOError: [Errno ftp error] [Errno 10060]错误的原因以及解决方法
IOError: [Errno ftp error] [Errno 10060] 原因是爬取页面过快造成暂时被网站ban掉的情况,设置time.sleep(1)就好,后来发现ban的时间不定,就自己动 ...
- urllib2.URLError: <urlopen error [Errno 10061] >
今天来运行以前的python脚本,结果报这个错:urllib2.URLError: <urlopen error [Errno 10061] > 原来是因为 解决方法:打开IE浏览器,依次 ...
- python运行报错:urllib2.URLError: <urlopen error [Errno 10061] >
Traceback (most recent call last): File "F:\adt-bundle-windows-x86_64-20140702\eclipse\workspac ...
- urllib2.URLError: <urlopen error [Errno 104] Connection reset by peer>
http://www.dianping.com/shop/8010173 File "综合商场1.py", line 152, in <module> httpC ...
- [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: URLError: <urlopen error [Errno 10061] Connection refused>
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: URLError: <urlopen error ...
- gerrit代码审核工具之“error unpack failed error Missing unknown”错误解决思路
使用gerrit代码审核工具时遇到error: unpack failed: error Missing unknown d6d7c89bd1d77f44c5c8e99437aaffbfc0684e7 ...
- XAMPP Error: Apache shutdown unexpectedly. 解决思路
我建议首先 运行在cmd中运行 (安装目录)apache/bin/httpd.exe 之后就很好确定错误的具体原因了,而不是根据下面的那样猜端口,比如我遇到的问题,就是配置的路径不存在导致的. 参考资 ...
- ava.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind (解决思路)
当我们在启动tomcat服务的时候报错信息:java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bin 分析:从错 ...
- urllib2.URLError: <ulropn error [Errno 10060] >
在抓网页的时候,如果抓取频率很高,很容易出现这个错误: 意思是服务器拒绝响应.解决的方法为,隔段时间再试,不过这个方法不靠谱.靠谱的方法是增加一个延迟函数 import time time.sleep ...
随机推荐
- C语言-存储类&作用域&生命周期&链接属性
1.概念解析(1)存储类 a.存储类就是存储类型,也就是描述C语言变量在何种地方存储. b.内存有多种管理办法:栈.堆.数据段.bss段..text段......一个变量的存储类属性就是描述这个变量存 ...
- Python 日期时间datetime 加一天,减一天,加减一小时一分钟,加减一年
计算年.月.日需要安装组件包 pip install python-dateutil 当前日期时间 import datetime print datetime.datetime.now() # 20 ...
- No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst
今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...
- 微服务基础——厉害了!API网关
微服务刚刚诞生的时候,人们将服务进行拆分,实现服务之间的松耦合,并且每个服务有专门的团队维护,然后客户端直接和各个子服务进行交互.比如,订单,商品,会员服务. 那么这种客户端直接和后端服务交互的方式会 ...
- day26(026-网络编程)
###26.02_网络编程(网络编程三要素之IP概述) IPv6:8组,每组4个16进制数. 1a2b:0000:aaaa:0000:0000:0000:aabb:1f2f ###26.03_网络编程 ...
- springboot-war
预览 1.pom.xml 与springboot-jar-web的区别是: 将 <packaging>jar</packaging> 替换成: <packaging> ...
- Tensorflow——用openpose进行人体骨骼检测
https://blog.csdn.net/eereere/article/details/80176007 参考资料code:https://github.com/ildoonet/tf-pose- ...
- Ubuntu无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
转自:http://hi.baidu.com/xiaobaishu 鸣谢: xuleibjtu2010的原创空间 1.终端输入 ps -aux ,列出进程.找到含有apt‘-get的进程,直接sud ...
- 两个exe共享内存数据
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- PAT Advanced 1086 Tree Traversals Again (25) [树的遍历]
题目 An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For exam ...