【解决方案】During handling of the above exception, another exception occurred:

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/weixin_40313634/article/details/100825533

问题

在大量访问网页时,有可能出现这种报错:

代码语言:javascript
复制
14-09-2019 12:1138 root: ERROR: HTTPSConnectionPool(host='www.mzitu.com', port=443): Max retries exceeded with url: /187465/31 (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f0bed634f98>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 137, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 67, in create_connection
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

或者这种报错:

代码语言:javascript
复制
14-09-2019 12:0251 root: ERROR: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 377, in _make_request
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

原因

但实际上都是同一种错误:

代码语言:javascript
复制
During handling of the above exception, another exception occurred:

而这都是由于频繁访问网站造成的

解决

在访问失败后,添加 time.sleep(), 然后重新访问即可。