【问题标题】:urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection ...>: Failed to establish a new connection: [Errno 111] Connection refusedurllib3.exceptions.NewConnectionError:<urllib3.connection.HTTPConnection ...>:无法建立新连接:[Errno 111] 连接被拒绝
【发布时间】:2019-06-03 09:40:26
【问题描述】:

为什么在 Selenium 中会看到这个错误;

urllib3.exceptions.NewConnectionError: &lt;urllib3.connection.HTTPConnection object at 0xsome_hex_address&gt;: Failed to establish a new connection: [Errno 111] Connection refused

什么时候使用各种功能?

【问题讨论】:

    标签: selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    请确保您没有在某个地方终止您的会话。例如(在 Python 中);

    import time
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    
    driver = webdriver.Chrome('/usr/bin/chromedriver',options=chrome_options)
    driver.get('https://www.somewebsite.com')
    try:
      WebDriverWait(driver,20).until(EC.presence_of_element_located((By.XPATH,"//input[@type='file']")))
    finally:
      driver.quit()
    WebDriverWait(driver,20).until(EC.presence_of_element_located((By.CLASS,"someclass")))
    

    第二个 WebDriverWait 将失败并显示上述错误消息,因为“try”的“finally”子句总是被执行,因此驱动程序退出/被关闭。因此,随后的 WebDriverWait 失败了。很容易错过。

    顺便说一下,在上面的例子中,如果尝试失败,您可以将“finally:”更改为“except:”以“仅”执行 driver.quit()。

    【讨论】:

      猜你喜欢
      • 2016-02-22
      • 1970-01-01
      • 2021-11-13
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2020-11-22
      • 2014-09-14
      相关资源
      最近更新 更多