且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MaxRetryError:HTTPConnectionPool:超过最大重试次数(由ProtocolError(“连接中止.",错误(111,“连接被拒绝")引起))

更新时间:2022-01-27 08:16:26

此错误消息...

MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=51379): Max retries exceeded with url: /session/2e64d2a1-3c7f-4221-96fe-9d0b1c102195/window (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))

...表示 get() 方法未能引发 MaxRetryError .

几件事:

  • 首先,根据讨论 max-retries-超出范围的异常令人困惑 traceback 有点误导.请求包装异常是为了方便用户.原始异常是显示的消息的一部分.
  • 请求永不重试(它为urllib3的HTTPConnectionPool设置了retries=0),因此如果没有 MaxRetryError HTTPConnectionPool ,该错误将更为规范. >关键字.因此理想的 Traceback 应该是:

  • First and foremost as per the discussion max-retries-exceeded exceptions are confusing the traceback is somewhat misleading. Requests wraps the exception for the users convenience. The original exception is part of the message displayed.
  • Requests never retries (it sets the retries=0 for urllib3's HTTPConnectionPool), so the error would have been much more canonical without the MaxRetryError and HTTPConnectionPool keywords. So an ideal Traceback would have been:

ConnectionError(<class 'socket.error'>: [Errno 1111] Connection refused)

  • 但是@ sigmavirus24再次在他的评论中提到 ...包装这些异常会产生出色的API,但会带来不良的调试体验...

  • But again @sigmavirus24 in his comment mentioned ...wrapping these exceptions make for a great API but a poor debugging experience...

    根据 Selenium 3.14.1 发行说明:

    * Fix ability to set timeout for urllib3 (#6286)
    

    合并是:修复urllib3无法设置超时!

    一旦升级到 Selenium 3.14.1 ,您将可以设置超时并查看规范的 Tracebacks ,并且可以采取必要的措施.

    Once you upgrade to Selenium 3.14.1 you will be able to set the timeout and see canonical Tracebacks and would be able to take required action.

    几个相关的事件引用:

    • Adding max_retries as an argument
    • Removed the bundled charade and urllib3.
    • Third party libraries committed verbatim