python – ConnectionAbortedError:[WinError 10053]已建立的连接已被主机中的软件中止
出于某种原因,只有在我打开嵌套的webdriver实例时才会出现以下错误.不知道这里发生了什么.

我使用的是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:\Users\Anthony\Desktop\test.py", line 271, in <module>
    backers_profile = container.find_elements_by_xpath('./*/div[@class="campaignBackers-pledge-backer-details"]/a')
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 381, in find_elements_by_xpath
    return self.find_elements(by=By.XPATH, value=xpath)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 680, in find_elements
    {"using": by, "value": value})['value']
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 318, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1055, in _send_output
    self.send(chunk)
  File "C:\Users\Anthony\AppData\Local\Programs\Python\Python37\lib\http\client.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,,因为它太长了!

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('\nSection: Function to Create Instances of WebDriver\nCulprit: random.choice(ua_strings)\nIndexError: {}\n'.format(error))
        return webdriver.Firefox() # firefox_options=options

有没有人知道可能导致连接中止的原因是什么?

最佳答案
正如 documentation所说:

Software caused connection abort. An established connection was
aborted by the software in your host computer, possibly due to a data
transmission time-out or protocol error.

可能的原因:

>超时或其他网络级错误.
>网络连接已经死亡
>防火墙因为打开时间太长而关闭了连接
>在完成流程之前已关闭连接
> AntiVirus会阻止连接

等等.

同时尝试将geckodriver 0.21.0降级为geckodriver 0.20.1.你可以下载它here.这似乎是geckodriver 0.21.0 https://stackoverflow.com/a/51236719/8625512的一个问题

PS:

options.add_argument('-headless')

应该:

options.add_argument('--headless')
点击查看更多相关文章

转载注明原文:python – ConnectionAbortedError:[WinError 10053]已建立的连接已被主机中的软件中止 - 乐贴网