文档章节

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

z
 zb1021
发布于 2017/07/31 12:03
字数 928
阅读 720
收藏 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爬虫:爬取资源站点列表

发现某站点文章很多,爬取所有文章名和链接,并保存在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
nginx proxy超时报错 upstream timed out (110: Connec...

环境介绍 服务器:centos5.8 服务:nginx proxy 问题描述: php的某些页面打不开,页面提示gateway timeout,然后查找日志提示如下 2012/09/19 14:00:30 [error] 1811#0: *319 upstream time...

foxidea
2012/12/30
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

idea新建springCloud项目(5)- 订单服务

1.创建订单api,如下: 2.创建订单实现逻辑 3.新建订单、订单商品表 -- 订单 create table `order_master` ( `order_id` varchar(32) not null, `buyer_name` varchar(32) not null comment......

monroeCode
16分钟前
1
1
游戏开发经验谈(二):对战类全球服游戏的设计与实现

上篇文章《游戏开发经验谈(一):游戏架构里隐藏的五个坑及其应对方案》,我们主要讲解了游戏架构设计当中隐藏的一些坑及其应对方案,错过的小伙伴可以回溯之前的内容。本期内容,将会重点介...

UCloudTech
26分钟前
0
0
Mysql基本语法

一.联合主键 drop table CONTENT_AND_CATALOG;CREATE TABLE `tobebetter`.`CONTENT_AND_CATALOG` ( `ID` VARCHAR(120) NOT NULL , `CONTENT_ID` VARCHAR(120) , `CA......

我是菜鸟我骄傲
27分钟前
0
0
179. centos7 安装mariadb

1. centos7 中安装mariadb 1.1 执行安装 centos7 自带了mariadb yum -y install mariadb mariadb-server 1.2 启动mariadb systemctl start mariadb 1.3 设置开机启动 systemctl enable maria......

Lucky_Me
35分钟前
0
0
【AI实战】动手训练自己的目标检测模型(YOLO篇)

在前面的文章中,已经介绍了基于SSD使用自己的数据训练目标检测模型(见文章:手把手教你训练自己的目标检测模型),本文将基于另一个目标检测模型YOLO,介绍如何使用自己的数据进行训练。 ...

雪饼
41分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部