爬虫代理池测试代理异常报错:concurrent.futures._base.TimeoutError

冬天的风好冷 2019-04-16 09:34:45
代码来看自崔庆才《python3网络爬虫开发实战》书中第九章代理的使用,里面有三个模块一个获取代理 ,一个api,还有一个就是测试代理是否可用,出问题的就是这个测试,运行后不一会就报异常,但是奇怪的是这个测试还是会运行并且整理出可以用的代理,只是会报异常,不清楚具体是什么原因?我如何才能处理这个异常???知道原因请告知,谢谢!! 异常代码: 代理池开始运行 Task exception was never retrieved future: <Task finished coro=<Tester.test_single_proxy() done, defined at K:\mycode\proxy_demo\src\tester.py:21> exception=TimeoutError()> Traceback (most recent call last): File "K:\mycode\proxy_demo\src\tester.py", line 36, in test_single_proxy async with session.get(TEST_URL,proxy=real_proxy,timeout=15) as response: File "D:\Program Files\Python37\lib\site-packages\aiohttp\client.py", line 1005, in __aenter__ self._resp = await self._coro File "D:\Program Files\Python37\lib\site-packages\aiohttp\client.py", line 575, in _request break File "D:\Program Files\Python37\lib\site-packages\aiohttp\helpers.py", line 585, in __exit__ raise asyncio.TimeoutError from None concurrent.futures._base.TimeoutError 本地环境是python3.7.2,虚拟机用的是redis数据库
...全文
668 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
尘封记忆 2019-04-18
  • 打赏
  • 举报
回复


import requests


url = 'https://www.163.com'


def _simple_request():
	response = requests.get(url)
	print("simple_request:response.status_code %s" % response.status_code)
	print("simple_request:len(response.text) %s" % len(response.text))


def _request_proxies():
	proxies = {
		'http': 'http://115.196.48.33:9000'
	}

	response = requests.get(url, proxies=proxies)
	print("request_proxies:response.status_code %s" % response.status_code)
	print("request_proxies:len(response.text) %s" % len(response.text))


if __name__ == "__main__":
	_simple_request()
	_request_proxies()

我暂时没有py3,用的是requests,用不用代理获取的数据是一样,只能说明,你的代理是不是过期了。
尘封记忆 2019-04-16
  • 打赏
  • 举报
回复
没代码 应该是代理的IP有问题,导致获取数据超时了。
冬天的风好冷 2019-04-16
  • 打赏
  • 举报
回复
引用 1 楼 ksx_120999 的回复:
没代码 应该是代理的IP有问题,导致获取数据超时了。
我上传到了github,帮我看下呗,谢谢 代码库地址:https://github.com/winter-wind/proxy_demo.git 主要是tester.py这个源码问题? 这个代码能用,能整理出可用代理,我就是想处理这个异常,不让他出现。

37,722

社区成员

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

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