文档章节

requests.exceptions.ReadTimeout: HTTPConnectionPool(host='img.qqzhi.com', port=80): Read timed out.

z
 zb1021
发布于 2017/07/31 12:03
字数 928
阅读 925
收藏 0
"C:\Program Files\Python36\python.exe" C:/Users/Administrator.SC-201612181954/PycharmProjects/untitled2/test1
http://www2.bingfeng.tw/data/attachment/forum/201601/21/150057zygjy5rf2y5spf2y.png
http://i-3.yxdown.com/2016/5/19/b24c1344-5524-4f35-96e2-cd1db694d563.jpg
http://i-3.yxdown.com/2016/5/19/b43738d9-5523-4659-a8fe-19b838650af8.jpg
http://attach10.92wy.com/images/2016/0111/1452497908993e6d86.jpg
http://www2.bingfeng.tw/data/attachment/forum/201601/21/150234lsabgyz2yg00ji00.jpg
http://attach10.92wy.com/images/2016/0111/14524963748832cf37.jpg
http://img.qqzhi.com/upload/img_2_2950581147D1797566349_23.jpg
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Program Files\Python36\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Program Files\Python36\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Program Files\Python36\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Program Files\Python36\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\requests\adapters.py", line 440, in send
    timeout=timeout
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\util\retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\packages\six.py", line 686, in reraise
    raise value
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 389, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 309, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='img.qqzhi.com', port=80): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Administrator.SC-201612181954/PycharmProjects/untitled2/test1", line 12, in <module>
    pic= requests.get(each, timeout=10)
  File "C:\Program Files\Python36\lib\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Program Files\Python36\lib\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Program Files\Python36\lib\requests\sessions.py", line 502, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Program Files\Python36\lib\requests\sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "C:\Program Files\Python36\lib\requests\adapters.py", line 516, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='img.qqzhi.com', port=80): Read timed out. (read timeout=10)

具体学爬虫的过程中遇到了这个问题,按照网络上面的教程,爬图片爬到一半就卡死了,下面是代码

import re
import requests

#url = 'http://image.baidu.com/search/flip?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1460997499750_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E5%B0%8F%E9%BB%84%E4%BA%BA'
url = 'http://image.baidu.com/search/flip?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1501470791167_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&ctd=1501470791180%5E00_1899X935&word=%E5%9B%A2%E5%AD%90%E5%B0%91%E5%A5%B3'
html = requests.get(url).text
pic_url = re.findall('"objURL":"(.*?)",',html,re.S)
i = 0
for each in pic_url:
    print(each)
    try:
        pic= requests.get(each, timeout=10)
    except requests.exceptions.ConnectionError:
        print( '【错误】当前图片无法下载')
        continue
    string = 'picture1\\'+str(i) + '.jpg'
    fp = open(string,'wb')
    fp.write(pic.content)
    fp.close()
    i += 1

检查以后发现是百度所在的页面该图片虽然收录在自己的机器上,所以你还能看见,但是实际连接已经失效,只能在缩略图上看到

仔细查看错误信息发现返回的错误信息是

requests.exceptions.ReadTimeout:

而不是代码中的

except requests.exceptions.ConnectionError:

我查了一下这两个错误的区别,发现区别不是很大,一般来说readtimeout出现的原因是该网页点击以后加载特别慢,而后者就是直接显示连接错误类型的,大部分的人在验证这里的连接错误的时候都是同时加的验证(这里也对这个程序原来的作者表示不要偷懒,博客上教东西教一半,太坑爹了)

© 著作权归作者所有

共有 人打赏支持
z
粉丝 1
博文 17
码字总数 9047
作品 0
石景山
程序员
python操作elasticsearch,在用helper.bulk时,数据插入到四千多条的时候会报超时,请问如何解决?

从接口里面读到数据,处理之后将数据批量插入es,但是会报超时,我已经设置超时时间为120秒了,环境的linux 批量插入代码如下: elasticsearch.helpers.bulk(es, actions, request_timeout=...

何法
09/09
0
0
Python爬虫:爬取资源站点列表

发现某站点文章很多,爬取所有文章名和链接,并保存在txt文档中,方便后续查看 #!/usr/bin/python -- coding: UTF-8 -- import urllib,urllib2,re,requestsimport sysreload(sys)sys.setdef...

M四月天
06/26
0
0
PS-Scan ports扫描网络端口

用PS写出端口扫描 TCP139/445 AND UDP 137/138 用法简单:在c:temptarget.txt写入多台IP地址 端口可以自己定义 以下是代码: <# This script can be used to Scan port TCP139/445 AND UDP 13......

bilinyee
2017/05/16
0
0
nginx +phpfastcgi 环境下 导出excel文件,超时,数据被截断问题,解决

nginx 错误日志显示,访问超时 2015/09/16 07:18:43 [error] 2108#0: *6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1......

蜗牛奔跑
2015/09/16
781
0
在用Python进行图片抓取时,request出现以下的错误信息

在进行Python网页图片抓取时,出现以下错误信息,烦请各位大佬指教一下这个错误如何解决: Traceback (most recent call last): File "D:JAVAworkspacepachongpachong_init_.py", line 29, i...

朱季谦
06/06
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Spring IOC 之 注册 BeanDefinition

获取 Document 对象后,会根据该对象和 Resource 资源对象调用 registerBeanDefinitions() 方法,开始注册 BeanDefinitions 首先调用 createBeanDefinitionDocumentReader() 方法实例化 Bean...

职业搬砖20年
7分钟前
0
0
Pycahrm左边出现一些bookmark的取消方法

pycharm 左边出一个对号或则一个0,放上去提示Bookmark 取消方法:按F11

鹏灬
10分钟前
0
0
JDK1.8使用Dubbo时需注意

Dubbo自带的很多包都比较旧了,其中的javassist在JDK1.8上运行会报错 而且错误通常比较诡异,javassist是编辑和创建Java字节码的类库,常见的错误会从spring中报出 解决办法: <dependency>...

火龙战士
12分钟前
0
0
Java 对Oracle数据库中的 BLOB类型 插入图片

package test;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.PrintStream;import java.sql.Connection;import java.sql.DriverManager;......

青峰Jun19er
14分钟前
0
0
awk复习

10月22日任务 复习 awk调用外部变量 -v参数设置内部变量调用外部变量 [root@test awk]# a=44[root@test awk]# echo "ABCD" | awk -v GET_A=$a '{print GET_A}'44 更复杂的应用: [root@...

robertt15
22分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部