此错误消息…
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’)))
…表示该 方法无法引发 。
有两件事:
首先,根据讨论,max-retries-exceeded异常令人困惑, 回溯 有些误导。请求包装异常是为了方便用户。原始异常是显示的消息的一部分。请求永不重试(它retries=0为urllib3 设置了httpconnectionPool),因此如果没有 和 关键字,则错误将更为规范。因此理想的 回溯 应该是:
ConnectionError(<class ’socket.error’>: [Errno 1111] Connection refused)
但是@ sigmavirus24在他的评论中再次提到 …包装这些异常会产生出色的API,但会带来不良的调试体验…
向前推进的计划是 尽可能向下遍历最低级别的异常,并使用它。
最后,通过改写一些与实际连接被拒绝错误无关的异常来解决此问题。解由于按照 发行说明 的 :
* Fix ability to set timeout for urllib3 (#6286)
该 合并 是:维修urllib3不能设置超时!
结论升级到 您将可以设置超时并查看规范的 回溯 ,并且可以采取必要的措施。
参考资料几个相关的事件引用:
添加max_retries作为参数删除了捆绑的charade和urllib3。第三方图书馆逐字承诺解决方法我有一个问题:我想测试“选择”和“输入”。我可以像下面的代码一样写吗:原始代码:
12 class Sinaselecttest(unittest.TestCase): 13 14 def setUp(self): 15 binary = FirefoxBinary(’/usr/local/firefox/firefox’) 16 self.driver = webdriver.Firefox(firefox_binary=binary) 17 18 def test_select_in_sina(self): 19 driver = self.driver 20 driver.get('https://www.sina.com.cn/') 21 try: 22 WebDriverWait(driver,30).until( 23 ec.visibility_of_element_located((By.XPATH,'/html/body/div[9]/div/div[1]/form/div[3]/input')) 24 ) 25 finally: 26 driver.quit() # #测试select功能 27 select=Select(driver.find_element_by_xpath('//*[@id=’slt_01’]')).select_by_value('微博') 28 element=driver.find_element_by_xpath('/html/body/div[9]/div/div[1]/form/div[3]/input') 29 element.send_keys('杨幂') 30 driver.find_element_by_xpath('/html/body/div[9]/div/div[1]/form/input').click() 31 driver.implicitly_wait(5) 32 33 34
我想测试Selenium的“选择”功能。所以我选择sina网站选择一个选项,然后在textarea中输入文本。然后搜索它。但是当我运行此测试时,它有错误:
Traceback (most recent call last): File 'test_sina_select.py',line 32,in tearDownself.driver.close() File '/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py',line 688,in closeself.execute(Command.CLOSE) File '/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py',line 319,in executeresponse = self.command_executor.execute(driver_command,params) File '/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py',line 376,in executereturn self._request(command_info[0],url,body=data) File '/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py',line 399,in _requestresp = self._conn.request(method,body=body,headers=headers) File '/usr/lib/python2.7/site-packages/urllib3/request.py',line 68,in request**urlopen_kw) File '/usr/lib/python2.7/site-packages/urllib3/request.py',line 81,in request_encode_urlreturn self.urlopen(method,**urlopen_kw) File '/usr/lib/python2.7/site-packages/urllib3/poolmanager.py',line 247,in urlopenresponse = conn.urlopen(method,u.request_uri,**kw) File '/usr/lib/python2.7/site-packages/urllib3/connectionpool.py',line 617,in urlopenrelease_conn=release_conn,**response_kw) File '/usr/lib/python2.7/site-packages/urllib3/connectionpool.py',line 597,in urlopen_stacktrace=sys.exc_info()[2]) File '/usr/lib/python2.7/site-packages/urllib3/util/retry.py',line 271,in incrementraise MaxRetryError(_pool,error or ResponseError(cause)) 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’))) ---------------------------------------------------------------------- Ran 1 test in 72.106s
谁能告诉我为什么?谢谢