ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止 [英] ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

查看:66
本文介绍了ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,当我打开嵌套的 webdriver 实例时,only 出现以下错误.不知道这里发生了什么.

For some reason I get the following error only when I open up a nested webdriver instance. No idea what is happening here.

我正在使用 Windows 10、 geckodriver 0.21.0、Python 3.7.

ConnectionAbortedError:[WinError 10053]

An established connection was aborted by the software in your host machine

运行良好的部分脚本

tab_backers = ff.find_element_by_xpath('//a[@gogo-test="backers_tab"]')

try:
    funding_backers_count = int(''.join(filter(str.isdigit, str(tab_backers.text))))
except ValueError:
    funding_backers_count = 0

if funding_backers_count > 0:
    tab_backers.click()

    see_more_backers = WebDriverWait(ff, 10).until(
        EC.element_to_be_clickable((By.XPATH, '//ui-view//a[text()="See More Backers"]'))
    )
    clicks = 0
    while clicks < 0:
        clicks += 1
        ff.WebDriverWait(ff, 5).until(
            see_more_backers.click()
        )

    for container in ff.find_elements_by_xpath('//ui-view//div[@class="campaignBackers-pledge ng-scope"]'):
        backers_profile = container.find_elements_by_xpath('./*/div[@class="campaignBackers-pledge-backer-details"]/a')
        if len(backers_profile) > 0:
            backers_profile = backers_profile[0].get_attribute('href') 
        else:
            backers_profile = 'Unknown'
        backers_name = safe_encode(container.find_element_by_xpath('(./*/div[@class="campaignBackers-pledge-backer-details"]/*)[1]').text)
        backers_timestamp = container.find_element_by_xpath('./*/div[@class="campaignBackers-pledge-backer-details"]/div[contains(@class, "campaignBackers-pledge-backer-details-note")]').text
        backers_contribution = container.find_element_by_xpath('./*//*[contains(@class, "campaignBackers-pledge-amount-bold")]').text
        if backers_contribution != 'Private':
            backers_contribution = int(''.join(filter(str.isdigit, str(backers_contribution))))
        if backers_profile != 'Unknown':

部分脚本导致系统中止连接

            _ff = create_webdriver_instance()
            _ff.get(backers_profile)
            _ff.quit()

追溯

Traceback (most recent call last):
  File "C:UsersAnthonyDesktop	est.py", line 271, in <module>
    backers_profile = container.find_elements_by_xpath('./*/div[@class="campaignBackers-pledge-backer-details"]/a')
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebelement.py", line 381, in find_elements_by_xpath
    return self.find_elements(by=By.XPATH, value=xpath)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebelement.py", line 680, in find_elements
    {"using": by, "value": value})['value']
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emotewebdriver.py", line 318, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emote
emote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriver
emote
emote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libhttpclient.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libhttpclient.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libhttpclient.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libhttpclient.py", line 1055, in _send_output
    self.send(chunk)
  File "C:UsersAnthonyAppDataLocalProgramsPythonPython37libhttpclient.py", line 977, in send
    self.sock.sendall(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

geckodriver.log

这是在 codepen 中,因为它太长了!

Here it is in a codepen, since it is wayyy too long!

create_webdriver_instance 函数

def create_webdriver_instance():
    options = Options()
    options.add_argument('-headless')
    try:
        ua_string = random.choice(ua_strings)
        profile = webdriver.FirefoxProfile()
        profile.set_preference('general.useragent.override', ua_string)
        return webdriver.Firefox(profile) # profile, firefox_options=options
    except IndexError as error:
        print('
Section: Function to Create Instances of WebDriver
Culprit: random.choice(ua_strings)
IndexError: {}
'.format(error))
        return webdriver.Firefox() # firefox_options=options


有人知道可能导致连接中止的任何原因吗?



Does anybody have any idea whatsoever what might be causing the connection to abort?


推荐答案

此错误信息...

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

...表示新的WebBrowsing Session 的初始化,即Firefox 浏览器 会话被中止.

...implies that the initialization of a new WebBrowsing Session i.e. Firefox Browser session was aborted.

根据您的代码尝试,错误显然来自 create_webdriver_instance() 函数,其中包含:

As per your code attempt the error is clearly coming out create_webdriver_instance() function which contains:

try:
    ua_string = random.choice(ua_strings)
    profile = webdriver.FirefoxProfile()
    profile.set_preference('general.useragent.override', ua_string)
    return webdriver.Firefox(profile)

还有:

except IndexError as error:
    print('
Section: Function to Create Instances of WebDriver
Culprit: random.choice(ua_strings)
IndexError: {}
'.format(error))
    return webdriver.Firefox()

因此,在 return webdriver.Firefox(profile)webdriver.Firefox() 中,您不清楚是从哪个函数中遇到此问题的.

So it is not exactly clear from which function you are facing this issue among return webdriver.Firefox(profile) or webdriver.Firefox().

也许仔细看看 codepen 表明错误来自 webdriver.Firefox(profile).

Perhaps a closer look at the logs within codepen suggests the error is coming out from webdriver.Firefox(profile).

此错误背后可能有多种原因:

There can be multiple reason behind this error:

  • 存在防病毒软件.
  • 防火墙阻止端口.
  • 网络配置.
  • 问题可能由 CORS 引起.
  • 由于启用了 HTTP 保持活动连接

第一步是查明是否有任何软件阻止了与您计算机中的服务器的连接.除此之外,可能的解决方案是:

The initial step would be find out if any software is blocking the connection to/from the server in your computer. Apart from that the probable solutions are:

  • 禁用杀毒软件.
  • 禁用防火墙.
  • 确保您系统上的/etc/hosts 包含以下条目:

  • Disable anti-virus softwares.
  • Disable firewall.
  • Ensure that /etc/hosts on your system contains the following entry:

127.0.0.1   localhost.localdomain localhost

  • 根据连接被主机中的软件中止 你需要允许像 http://localhost:8080/reactive-commands

    根据 与 geckodriver 0.21.0 的 Keep-Alive 连接在 5 秒没有活动后断开使用 Selenium Python 客户端重新连接

    AutomatedTester:这个问题不是因为我们在执行请求时没有连接.如果这是问题,我们将抛出 httplib.HTTPConnection 异常.相反,当我们建立连接并关闭它并尝试解析响应时,会抛出 BadStatusLine.现在这可能是 python stdlib 错误、httplib 错误或 selenium 错误.将 urllib 替换为与 Keep-Alive 连接没有相同缺陷的其他内容的 Python 客户端是 WIP.

    AutomatedTester: This issue is not because we are not connected at the time of doing a request. If that was the issue we would be getting a httplib.HTTPConnection exception being thrown. Instead a BadStatusLine is thrown when we do a connection and close it and try parse the response. Now this could be the python stdlib bug, httplib bug or selenium bug. A Python client to replace urllib with something else that does not exhibit the same defect with Keep-Alive connections is WIP.

  • andreastt:geckodriver 团队正在努力将服务器端超时值扩展到更合理的值.正如我所说,这将有助于缓解这个问题,但不能从根本上解决它.无论如何,5 秒可能太短而无法从持久 HTTP 连接中获得真正的好处,而将其增加到 60 秒之类的时间会获得更好的性能.

    andreastt: The geckodriver team is working on extending the server-side timeout value to something more reasonable. As I said, this would help mitigate this issue but not fundamentally fix it. In any case it is true that five seconds is probably too low to get real benefit from persistent HTTP connections, and that increasing it to something like 60 seconds would have greater performance.

  • Selenium 3.14.0 刚刚发布.如果您受到此问题的影响,请相应升级.

    Selenium 3.14.0 has just been released. If you are affected by this issue please upgrade accordingly.

    参考文献:

    这篇关于ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆