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

  • 2019 年 10 月 10 日
  • 筆記

版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。

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

問題

在大量訪問網頁時,有可能出現這種報錯:

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:

或者這種報錯:

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:

原因

但實際上都是同一種錯誤:

During handling of the above exception, another exception occurred:

而這都是由於頻繁訪問網站造成的

解決

在訪問失敗後,添加 time.sleep(), 然後重新訪問即可。