为了账号安全,请及时绑定邮箱和手机立即绑定

MaxRetryError:HTTPConnectionPool:超出最大重试次数(

MaxRetryError:HTTPConnectionPool:超出最大重试次数(

米脂 2019-09-06 15:44:51
我有一个问题:我想测试“选择”和“输入”。我可以像下面的代码一样编写它:原始代码:     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“select”函数。所以我选择sina网站选择一个选项并在textarea中输入文本。然后搜索它。但是当我运行这个测试时,它有错误: Traceback (most recent call last):      File "test_sina_select.py", line 32, in tearDown        self.driver.close()      File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 688, in close        self.execute(Command.CLOSE)      File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute        response = self.command_executor.execute(driver_command, params)      File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 376, in execute        return self._request(command_info[0], url, body=data)      File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 399, in _request        resp = self._conn.request(method, url, body=body, headers=headers)谁能告诉我为什么?谢谢
查看完整描述

3 回答

?
慕桂英546537

TA贡献1848条经验 获得超10个赞

此错误消息...


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-exceeded异常令人困惑,回溯有点误导。请求包装异常以方便用户。原始异常是显示的消息的一部分。

请求永远不会重试(它设置retries=0for urllib3 HTTPConnectionPool),因此如果没有MaxRetryError和HTTPConnectionPool关键字,错误会更加规范。所以理想的Traceback应该是:


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

但是@ sigmavirus24在他的评论中再次提到......包装这些异常会产生一个很好的API但调试经验不佳......


继续前进的计划是尽可能向下遍历到最低级别的异常并使用它。

最后,通过重写一些与实际连接拒绝错误无关的异常来解决此问题。

由于按照发行说明的硒3.14.1:


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

该合并是:修复urllib3不能设置超时!


结论

升级到Selenium 3.14.1后,您将能够设置超时并查看规范的回溯并能够采取必要的操作。


查看完整回答
反对 回复 2019-09-06
?
忽然笑

TA贡献1806条经验 获得超5个赞

刚遇到同样的问题。解决方案是使用脚本递归更改文件夹的所有者。在我的情况下,该文件夹具有root:root所有者:组,我需要将其更改为ubuntu:ubuntu。


解: sudo chown -R ubuntu:ubuntu /path-to-your-folder


查看完整回答
反对 回复 2019-09-06
?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

    ,我认为“选择”功能错误,原来是超时原因。对你来说,我会尝试升级我的Selenium并修改我的“选择”。


查看完整回答
反对 回复 2019-09-06
  • 3 回答
  • 0 关注
  • 10209 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信