ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止

2023-12-14

由于某种原因,我收到以下错误only当我打开一个嵌套的webdriver实例。不知道这里发生了什么。

我在用Windows 10, 壁虎驱动程序 0.21.0, and Python 3.7。

连接中止错误:[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


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



这个错误信息...

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

...意味着初始化一个新的网页浏览会话 i.e. 火狐浏览器会话被中止。


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

根据您的代码尝试,错误明显出现create_webdriver_instance()函数包含:

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

And:

except IndexError as error:
    print('\nSection: Function to Create Instances of WebDriver\nCulprit: random.choice(ua_strings)\nIndexError: {}\n'.format(error))
    return webdriver.Firefox()

因此,目前尚不清楚您在哪个功能中面临这个问题return webdriver.Firefox(profile) or webdriver.Firefox().

也许仔细看看里面的日志codepen表明错误来自webdriver.Firefox(profile).


Reasons

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

  • 的存在防病毒软件.
  • 防火墙阻止端口。
  • 网络配置。
  • 问题可能由以下原因引起CORS.
  • 由于启用了 HTTP keep-alive 连接

Solution

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

  • Disable 防病毒软件.
  • Disable firewall.
  • 确保系统上的 /etc/hosts 包含以下条目:

    127.0.0.1   localhost.localdomain localhost
    
  • As per 连接被主机中的软件中止你需要允许本地主机路由,例如http://localhost:8080/reactive-commands

  • As per 与 geckodriver 0.21.0 的保持活动连接在 5 秒不活动后断开,且未使用 Selenium Python 客户端重新连接

    • 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: 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刚刚被释放。如果您受到此问题的影响,请进行相应升级。


参考:

  • 带有请求的 Flask 破损管道
  • 跨域资源共享 (CORS)
  • 连接被主机中的软件中止
  • [WinError 10053] 与 0.21.0
  • 与 geckodriver 0.21.0 的保持活动连接在 5 秒不活动后断开,且未使用 Selenium Python 客户端重新连接
  • 支持保持连接
  • 结构体 hyper::server::Server
  • Urllib3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止 的相关文章

随机推荐

  • 从表中选择 *,其中日期 = 今天

    需要 PHP MySql 帮助 需要选择 今天 的所有记录 我的表有一列包含 unix 时间戳 我只想从表中选择 unix 时间戳 今天 很高兴在 Linux 命令行上执行此操作 只需要基本的 MySql 查询 我会选择 SQL 版本 SE
  • 显示 BLOB 图像 Laravel 4

    我在 mysql 上添加了 png 图像作为 BLOB 但是当我尝试检索它们时 我将它们作为文件获取 但无法显示为图像 下面是我的代码 控制器 public function post news image Input file image
  • 控制 ASP.Net MVC 中的输出缩进

    我的同事非常 热衷 将格式正确且缩进的 html 传送到客户端浏览器 这是为了使页面源代码易于被人阅读 首先 如果我有一个在站点中多个不同区域使用的部分视图 渲染引擎是否应该自动为我设置缩进格式 例如在 XmlTextWriter 上设置
  • ImageView圆角[重复]

    这个问题在这里已经有答案了 我希望图像有圆角 我实现了这个 xml 代码并在我的图像视图中使用它 但图像与形状重叠 我正在通过异步任务下载图像
  • ios音频单元remoteIO录音时播放

    我被要求将 VOIP 添加到游戏中 跨平台 因此无法使用 Apple gamekit 来做到这一点 已经有三四天了 我一直在努力让我的注意力集中在音频单元和远程IO上 我忽略了数十个示例等 但每次都只是对输入 PCM 应用简单的算法并在扬声
  • 使用 NSXMLParser 解析 XML

    我有一个关于 xml 解析的问题 通常 XML文件的样式是这样的
  • 如何在spark scala中使用带有2列的array_contains?

    我有一个问题 我想检查字符串数组是否包含另一列中存在的字符串 我目前正在使用下面的代码 该代码给出了错误 withColumn is designer present when array contains col list of desi
  • R 中的双冒号 (::) 是什么?

    我正在关注 Rbloggers 中的教程 发现双冒号的使用 我在网上查找 但找不到其使用的解释 这是它们的使用示例 df lt dplyr data frame year c 2015 NA NA NA trt c A NA B NA 我知
  • Greasemonkey @require 在 Chrome 中不起作用

    我正在尝试使用 Greasemonkey 添加 jQuery require include方法 但是不起作用 显示以下错误 Uncaught ReferenceError is not defined repeated 10 times
  • WinForm c#:检查首次运行并显示消息

    我正在创建一个包含首次运行检查的 winform 应用程序 我一直在关注这两篇文章 如何检查程序是否是第一次运行 C 中的 Windows 窗体用户设置 首次运行检查应该检查应用程序是否曾经运行过 如果没有运行过 它应该向用户显示一些消息
  • 在 TypeScript 中扩展特定类型的数组

    我知道如何扩展任何类型的数组 declare global interface Array
  • MongoDB NodeJS 本机驱动程序(mongodb) 与 Mongo Shell 性能对比

    我在 MongoDB 表 1 中有 10000 条记录 数据如下 id ObjectId 5d5e500cb89312272cfe51fc cities cityid 5d5d2205cdd42d1cf0a92b33 value XYZ c
  • Android 活动识别不适用于 Nexus 5

    我有一个正在使用谷歌活动识别更新的代码 现在突然之间 这些似乎每秒发送几次更新 或者从不发送更新 尽管每 20 秒请求一次 我没有更改代码并检查了早期版本 但遇到了同样的问题 我根据教程构建了一个最小的示例 但我的 Nexus 5 设备没有
  • 量词与非量词

    我有一个关于量词的问题 假设我有一个数组 我想计算该数组的数组索引 0 1 和 2 declare const cpuA Array Int Int assert or select cpuA 0 0 select cpuA 0 1 ass
  • C 宏将字符串转换为 pascal 字符串类型

    我想要一些关于宏的想法 用于将预处理器定义的字符串转换为 pascal 类型字符串 然后能够使用宏来初始化 const char 数组等 像这样的事情会很棒 define P STRING CONV str const char strin
  • 以编程方式锁定或关闭屏幕

    我想要turn off 锁定屏幕以编程方式控制我的设备 目前 当我尝试时 DevicePolicyManager mDPM DevicePolicyManager getSystemService Context DEVICE POLICY
  • 在 C# 中自动完成文本框

    我正在尝试自动完成文本框 我正在从 Access 数据库检索值 仅数据表中的一个字段 如果有人可以帮助我 AutoCompleteStringCollection autoCompleteList new AutoCompleteStrin
  • 如何在android中改变位图图像的颜色?

    我正在开发一个 Android 应用程序 其中我将图像设置为 imageview 现在 我想以编程方式更改位图图像颜色 假设我的图像最初是红色的 现在我需要将其更改为橙色 我怎样才能做到这一点 请帮忙 这是我的代码 我设法改变不透明度 但我
  • Rails 路由和控制器模块 - 命名空间?

    我无法为我的控制器创建模块 也无法让我的路由指向控制器内的该模块 出现此错误 Routing Error uninitialized constant Api Fb 所以 这就是我的路线设置方式 namespace api do names
  • ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止

    由于某种原因 我收到以下错误only当我打开一个嵌套的webdriver实例 不知道这里发生了什么 我在用Windows 10 壁虎驱动程序 0 21 0 and Python 3 7 连接中止错误 WinError 10053 An es