【问题标题】:In Python3.6 (selenium module): ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine在 Python3.6(硒模块)中: ConnectionAbortedError: [WinError 10053] 已建立的连接被主机中的软件中止
【发布时间】:2018-12-12 02:54:34
【问题描述】:

我正在用“用 Python 自动化无聊的东西”一书(由 Al Sweigart 编写)学习 Python,但我遇到了网络抓取问题(第 11 章),即 selenium 模块。我正在 Python IDLE 中编写以下内容:

>>> from selenium import webdriver
>>> browser = webdriver.Firefox() # Here Windows command black window appears
                                  # and Mozilla Firefox with blank page opens
>>> browser.get('http://inventwithpython.com')
    Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    browser.get('http://inventwithpython.com')
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 326, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\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\forwa\AppData\Local\Programs\Python\Python36-32\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\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
    self.send(chunk)
  File "C:\Users\forwa\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
    self.sock.sendall(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

>>> browser.get('http://inventwithpython.com')

当我第一次写&gt;&gt;&gt; browser.get('http://inventwithpython.com')时,出现错误。当我第二次编写此命令时,Mozilla Firefox 浏览器会打开所需的网页。当我第三次编写命令时,再次发生 ConnectionAbortedError,依此类推 - 编写命令的奇数次 (1, 3, ...) 导致 ConnectionAbortedError,偶数次 (2, 4, .. .) 通过没有错误。 我试图关闭防病毒和防火墙,但没有帮助。请帮我解决这个问题。 附:我有 Windows 10 操作系统。

【问题讨论】:

  • 我 99% 确定这与 IDLE 无关,因此删除了标签。 100% 确定,从命令提示符或开始菜单“Python 3.6”,在“Python 3.6”下运行交互式 python,并给出相同的命令。如果我错了,请添加“Python-IDLE”,并请租给我的评论。抱歉,我对硒一无所知。
  • 我尝试在 Python 3.6.5 下的命令窗口(Windows 10 PowerShell)中给出相同的命令。结果与 Python IDLE 中的结果相同。
  • 感谢您的反馈。太多人从不回复 cmets。

标签: selenium-webdriver web-scraping python-3.6


【解决方案1】:

我是 Automate the Boring Stuff with Python 一书的作者。我在 Windows 10 机器上也遇到了这个错误。根据这个 StackOverflow 回答 https://stackoverflow.com/a/51005821/1893164 这似乎是 geckodriver 0.21.0 的问题。

对我有用的解决方法是安装旧版本的 geckodriver,0.20.1,您可以在此处下载:https://github.com/mozilla/geckodriver/releases/tag/v0.20.1

【讨论】:

  • 非常感谢您的回复!我下载了 geckodriver 0.20.1,然后将它放在 C:\Users\User\AppData\Local\Programs\Python\Python36-32\selenium\webdriver 文件夹中。然后我将此文件夹添加到系统环境变量列表中。以下代码正常工作:&gt;&gt;&gt; from selenium import webdriver&gt;&gt;&gt; browser = webdriver.Firefox()&gt;&gt;&gt; browser.get('http://inventwithpython.com')
猜你喜欢
  • 2019-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-02
  • 2019-06-25
  • 2020-05-22
  • 1970-01-01
  • 2021-11-12
相关资源
最近更新 更多