在爬取时出现这种错误,

ConnectionError: HTTPConnectionPool(host=‘xxx.xx.xxx.xxx’, port=xxxx): Max retries exceeded with url: /api/v1/login/ (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f7c98a867d0>: Failed to establish a new connection: [Errno 111] Connection refused’,))

于是搜索了网上很多文章,总结如下:
1.http连接太多没有关闭导致的,解决方法:

import requests
requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
s = requests.session()
s.keep_alive = False # 关闭多余连接
s.get(url) # 你需要的网址

2.访问次数频繁,被禁止访问,解决方法:使用代理

import requests
s = requests.session()
url = "https://mail.163.com/"
s.proxies = {"https": "47.100.104.247:8080", "http": "36.248.10.47:8080", }
s.headers = header
s.get(url)

查找代理的网址:http://ip.zdaye.com/shanghai_ip.html#Free
使用代理时需注意:
1.代理分为http和https两种,不能用混,如果把http的代理用作https也是会报上面的错误;
2.上面的代理以字典格式传入,例如上面的例子,可以是“47.100.104.247:8080”这种格式,也可以是“https://47.100.104.247:8080”这种格式;
3.如果代理不可用一样会报上面的错误。
以下方法判断代理是否可用:

import requests
s = requests.session()
url = "https://mail.163.com/"
s.keep_alive = False
s.proxies = {"https": "47.100.104.247:8080", "http": "36.248.10.47:8080", }
s.headers = header
r = s.get(url)
print r.status_code  # 如果代理可用则正常访问,不可用报以上错误
                    在爬取时出现这种错误,ConnectionError: HTTPConnectionPool(host=‘xxx.xx.xxx.xxx’, port=xxxx): Max retries exceeded with url: /api/v1/login/ (Caused by NewConnectionError(’&lt;urllib3.connection.HTTPConnection object at 0x7f7c98a867d0&gt;: Failed to establish a new c
具体方法:
User Agent减少IP被封次数,原理是模仿人的点击访问。
具体做法:加上headers={'user-agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.133 Safari/569.36'}
这里使用的是模仿谷歌浏览器的,其他浏览器可以参见这篇文章Python3网络爬虫(四):使用Us
  request = requests.get(url,timeout=60)
  #raise_for_status(),如果不是200会抛出HTTPError错误
  request.raise_for_status()
  html = request.content
				
某次在写爬虫时,运行之后报错 requests.exceptions.ProxyError: HTTPSConnectionPool(host=‘xxx.xxx.xxx’, port=443): Max retries exceeded with url: xxxxxxx (Caused by ProxyError (‘Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPSConnection object at
解决requests.exceptions.SSLError: HTTPSConnectionPool(host=xxxxx‘, port=443): Max retries exceeded
requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数 s = requests.session() s.keep_alive = False # 关闭多余连接 s.get(url) # 你需要的网址 2....
进行requests库学习的时候,报Max retries exceeded with url错误,网上查询说是,用下面这个解决方法没用,后来关闭了fiddler后发现就可以了,可能fiddler开的连接数太多了 http连接太多没有关闭导致的。 解决办法: 1、增加重试连接次数 requests.adapters.DEFAULT_RETRIES = 5 2、关闭多余的...
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: (Caused by <class 'socket.gaierror'>: python脚本请求url,大量请求报错Max retries exceeded with url
错误内容 requests.exceptions.ConnectionError: HTTPConnectionPool(host='baidu.com', port=80): Max retries exceeded with url: (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x2b09dfd00310>: Failed to establ
在本地机器上,高频率重复调用一个API接口,出现“Max retries exceeded with url”,拒绝连接的情况。 楼主讲一下,遇到这个bug的过程: 在服务器上开发了一个识别图像文字API接口,也部署好了,准备对接口进行测试, 楼主准备对本地文件夹中的2000多张图片进行测试,也就是说需要重复调用API接口2000多次。 请求接口50多次的时候,接口就不反馈信息了,报错,连接错误,无法连接,一开始以为是网络的问题,然后又重头开始调用直到调了300多次,报错,连接错误,无法连接,一直这么下去大
文章目录1、Max retries exceeded with url方法1、方法2403错误 1、Max retries exceeded with url 方法1、 出现这个错误可能跟爬取速度过快而且没有关闭每次的请求有关,导致出错。 requests使用了urllib3库,默认的http connection是keep-alive的,requests设置False关闭。 可以,每次请求的内容...
1.使用代理ip爬虫 我们在进行爬虫任务的时候经常会遇到网站设置的反爬关卡,比如限制单个ip一秒或者几秒内访问服务器几次,超过这个次数就把这个ip拉进"黑名单",我们一般自己的网络只有一个ip,ip封了就没办法继续访问这个网站了,那我们怎么办呢,我们可以使用别人的ip去访问啊,这样就算封了,我们再换一个就好了。 2。获取代理IP池 这里我是从一个资源网站找的https://www.kuaidaili.com/free/inha/{}/ 首先我们请求该网站,并解析页面。 proxy = [] #
python 报错 UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd3 in position 解决方法 weixin_46849434: 新加入这一行后显示NameError: name 'line' is not defined linux 内核编译错误 Makefile:416: *** mixed implicit and normal rules: deprecated syntax 在科学的海洋狗刨: 内核源码的主Makefile是在哪呢?