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

本文主要是介绍requests.exceptions.ReadTimeout: HTTPConnectionPool(host='img.qqzhi.com', port=80): Read timed out.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

"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_requestsix.raise_from(e, None)File "<string>", line 2, in raise_fromFile "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 383, in _make_requesthttplib_response = conn.getresponse()File "C:\Program Files\Python36\lib\http\client.py", line 1331, in getresponseresponse.begin()File "C:\Program Files\Python36\lib\http\client.py", line 297, in beginversion, status, reason = self._read_status()File "C:\Program Files\Python36\lib\http\client.py", line 258, in _read_statusline = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")File "C:\Program Files\Python36\lib\socket.py", line 586, in readintoreturn self._sock.recv_into(b)
socket.timeout: timed outDuring 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 sendtimeout=timeoutFile "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 incrementraise 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 reraiseraise valueFile "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 601, in urlopenchunked=chunked)File "C:\Program Files\Python36\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 389, in _make_requestself._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_timeoutraise 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 getreturn request('get', url, params=params, **kwargs)File "C:\Program Files\Python36\lib\requests\api.py", line 58, in requestreturn session.request(method=method, url=url, **kwargs)File "C:\Program Files\Python36\lib\requests\sessions.py", line 502, in requestresp = self.send(prep, **send_kwargs)File "C:\Program Files\Python36\lib\requests\sessions.py", line 612, in sendr = adapter.send(request, **kwargs)File "C:\Program Files\Python36\lib\requests\adapters.py", line 516, in sendraise 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( '【错误】当前图片无法下载')continuestring = 'picture1\\'+str(i) + '.jpg'fp = open(string,'wb')fp.write(pic.content)fp.close()i += 1

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

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

requests.exceptions.ReadTimeout:

而不是代码中的

except requests.exceptions.ConnectionError:

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

转载于:https://my.oschina.net/u/3471785/blog/1492631

这篇关于requests.exceptions.ReadTimeout: HTTPConnectionPool(host='img.qqzhi.com', port=80): Read timed out.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/303673

相关文章

nginx配置多域名共用服务器80端口

《nginx配置多域名共用服务器80端口》本文主要介绍了配置Nginx.conf文件,使得同一台服务器上的服务程序能够根据域名分发到相应的端口进行处理,从而实现用户通过abc.com或xyz.com直... 多个域名,比如两个域名,这两个域名其实共用一台服务器(意味着域名解析到同一个IP),一个域名为abc

一文详解如何在Python中使用Requests库

《一文详解如何在Python中使用Requests库》:本文主要介绍如何在Python中使用Requests库的相关资料,Requests库是Python中常用的第三方库,用于简化HTTP请求的发... 目录前言1. 安装Requests库2. 发起GET请求3. 发送带有查询参数的GET请求4. 发起PO

Nginx启动失败:端口80被占用问题的解决方案

《Nginx启动失败:端口80被占用问题的解决方案》在Linux服务器上部署Nginx时,可能会遇到Nginx启动失败的情况,尤其是错误提示bind()to0.0.0.0:80failed,这种问题通... 目录引言问题描述问题分析解决方案1. 检查占用端口 80 的进程使用 netstat 命令使用 ss

Python结合requests和Cheerio处理网页内容的操作步骤

《Python结合requests和Cheerio处理网页内容的操作步骤》Python因其简洁明了的语法和强大的库支持,成为了编写爬虫程序的首选语言之一,requests库是Python中用于发送HT... 目录一、前言二、环境搭建三、requests库的基本使用四、Cheerio库的基本使用五、结合req

Python 中 requests 与 aiohttp 在实际项目中的选择策略详解

《Python中requests与aiohttp在实际项目中的选择策略详解》本文主要介绍了Python爬虫开发中常用的两个库requests和aiohttp的使用方法及其区别,通过实际项目案... 目录一、requests 库二、aiohttp 库三、requests 和 aiohttp 的比较四、requ

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法   消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法 [转载]原地址:http://blog.csdn.net/x605940745/article/details/17911115 消除SDK更新时的“

vue 父组件调用子组件的方法报错,“TypeError: Cannot read property ‘subDialogRef‘ of undefined“

vue 父组件调用子组件的方法报错,“TypeError: Cannot read property ‘subDialogRef’ of undefined” 最近用vue做的一个界面,引入了一个子组件,在父组件中调用子组件的方法时,报错提示: [Vue warn]: Error in v-on handler: “TypeError: Cannot read property ‘methods

urllib与requests爬虫简介

urllib与requests爬虫简介 – 潘登同学的爬虫笔记 文章目录 urllib与requests爬虫简介 -- 潘登同学的爬虫笔记第一个爬虫程序 urllib的基本使用Request对象的使用urllib发送get请求实战-喜马拉雅网站 urllib发送post请求 动态页面获取数据请求 SSL证书验证伪装自己的爬虫-请求头 urllib的底层原理伪装自己的爬虫-设置代理爬虫coo

[轻笔记] pip install : Read timed out. (closed)

添加超时参数(单位秒) pip --default-timeout=10000 install ${package_name}

Cannot read property ‘length‘ of null while opening vscode terminal

同一问题地址:Cannot read property ‘length’ of null while opening vscode terminal 问题描述 One day, 我在ubuntu 18.04下用vscode打开一个项目,并想和往常一样在vscode使用终端,发现报错Cannot read property 'length' of null。 解决 打开setting.jso