[英]Python (Selenium) with MS Edge browser: 'Connection aborted.', ConnectionResetError(10054, ...) "Microsoft Web Driver has stopped working"
Every time I run my python code, the Edge browser opens but does not load the URL.每次运行 python 代码时,Edge 浏览器都会打开但不加载 URL。 Then Windows system displays a dialog saying:
然后Windows系统显示一个对话框说:
Microsoft Web Driver has stopped working.
Microsoft Web 驱动程序已停止工作。
A problem caused the program to stop working correctly.
一个问题导致程序停止正常工作。 Windows will close the program and notify you if a solution is available.
Windows 将关闭该程序并通知您是否有可用的解决方案。
My Python code: (Running on PyCharm):我的 Python 代码:(在 PyCharm 上运行):
# Locate the web driver for Edge browser
driver = webdriver.Edge(executable_path = 'C:/Users/username/webdrivers/MicrosoftWebDriver.exe')
# Open the website
driver.get("https://google.com")
Warning/Error Message from PyCharm:来自 PyCharm 的警告/错误消息:
Traceback (most recent call last): File "02042020.py", line 14, in driver = webdriver.Edge(executable_path = 'C:/Users/username/webdrivers/MicrosoftWebDriver.exe') File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\edge\\webdriver.py", line 61, in init RemoteWebDriver.
回溯(最近一次调用):文件“02042020.py”,第 14 行,在 driver = webdriver.Edge(executable_path = 'C:/Users/username/webdrivers/MicrosoftWebDriver.exe') 文件“C:\\Users\\username \\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\edge\\webdriver.py”,第 61 行,在init RemoteWebDriver 中。 init ( File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 319, in execute response = self.command_executor.execute(driver_command, params) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py", line 374, in execute return self._request(command_info[0], url, body=data) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py", line 402, in _request resp = http.request(method, url, body=body, headers=heade
init ( 文件 "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "C :\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py”,第 252 行,在 start_session 响应 = self.execute(Command.NEW_SESSION, parameters) 文件“C: \\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py”,第 319 行,在执行 response = self.command_executor.execute(driver_command, params) 文件“C:\\ Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py”,第 374 行,在执行 return self._request(command_info[0], url, body=data) 文件“ C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py”,第 402 行,在 _request resp = http.request(method, url, body=body, headers =头rs) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\request.py", line 79, in request return self.request_encode_body( File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\request.py", line 171, in request_encode_body return self.urlopen(method, url, **extra_kw) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\poolmanager.py", line 330, in urlopen response = conn.urlopen(method, u.request_uri, **kw) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\connectionpool.py", line 719, in urlopen retries = retries.increment( File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\util\\retry.py", line 400, in increment raise six.reraise(type(error), error, _stacktrace) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\packages\\six.py", line 734, in reraise raise value.with_traceback(tb) File "C:\\Users
rs) 文件 "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\request.py",第 79 行,在请求中返回 self.request_encode_body( 文件 "C:\\Users\\username\\PycharmProjects \\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\request.py", line 171, in request_encode_body return self.urlopen(method, url, **extra_kw) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv \\lib\\site-packages\\urllib3\\poolmanager.py",第 330 行,在 urlopen response = conn.urlopen(method, u.request_uri, **kw) File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\ lib\\site-packages\\urllib3\\connectionpool.py", line 719, in urlopen retries = retries.increment( File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\util\\retry .py”,第 400 行,以递增方式增加 6.reraise(type(error), error, _stacktrace) 文件“C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\packages\\six。 py”,第 734 行,重新加注提高 value.with_traceback(tb) 文件“C:\\Users \\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\connectionpool.py", line 665, in urlopen httplib_response = self._make_request( File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\connectionpool.py", line 421, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\connectionpool.py", line 416, in _make_request httplib_response = conn.getresponse() File "C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python38\\lib\\http\\client.py", line 1322, in getresponse response.begin() File "C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python38\\lib\\http\\client.py", line 303, in begin version, status, reason = self._read_status() File "C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python38\\lib\\http\\client.py", line 264, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "C:\\Users\\username\\AppData\\Local\\Programs\\Pytho
\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\site-packages\\urllib3\\connectionpool.py”,第 665 行,在 urlopen httplib_response = self._make_request( File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\ site-packages\\urllib3\\connectionpool.py", line 421, in _make_request Six.raise_from(e, None) File "", line 3, in raise_from File "C:\\Users\\username\\PycharmProjects\\Web_Scraping\\venv\\lib\\ site-packages\\urllib3\\connectionpool.py”,第 416 行,在 _make_request httplib_response = conn.getresponse() 文件“C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python38\\lib\\http\\client.py” ,第 1322 行,在 getresponse response.begin() 文件“C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python38\\lib\\http\\client.py”中,第 303 行,在开始版本中,状态,原因 = self._read_status() 文件“C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python38\\lib\\http\\client.py”,第 264 行,在 _read_status 行 = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") 文件 "C:\\Users\\username\\AppData\\Local\\Programs\\Pytho n\\Python38\\lib\\socket.py", line 669, in readinto return self._sock.recv_into(b)
n\\Python38\\lib\\socket.py”,第 669 行,在 readinto 中返回 self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, '一个现有的连接被远程主机强行关闭', None, 10054, None))
Environment details:环境细节:
I tried troubleshooting but it didn't work.我尝试进行故障排除,但没有奏效。
My troubleshooting:我的故障排除:
Enable Developer Mode which will install the appropriate version of WebDriver.启用开发人员模式,这将安装适当版本的 WebDriver。 On Windows:
在 Windows 上:
Settings > Update & Security > For developers > select "Developer Mode".
Running CMD as administrator to install via DISM :以管理员身份运行 CMD 以通过 DISM 安装:
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
It says:它说:
Deployment Image Servicing and Management tool
Version: 10.0.18362.1
Image Version: 10.0.18363.592
[==========================100.0%==========================]
The operation completed successfully.
I repeated these steps many times but it never worked.我多次重复这些步骤,但从未奏效。 I downloaded web driver for Chrome and switched my Python code to run with Chrome browser and it worked.
我下载了 Chrome 的网络驱动程序,并将我的 Python 代码切换为在 Chrome 浏览器上运行,并且它工作正常。 Unfortunately, the problem is that for this particular task, Microsoft Edge is the required browser.
不幸的是,问题在于对于这项特定任务,Microsoft Edge 是必需的浏览器。 Can someone please advise?
有人可以建议吗? Thanks in advance!
提前致谢!
Perhaps this issue occurs because you're using the Microsoft WebDriver version not matching the Microsoft Edge browser version.出现此问题的原因可能是您使用的 Microsoft WebDriver 版本与 Microsoft Edge 浏览器版本不匹配。 As far as I know, when we install the Microsoft Edge webdriver via DISM, by default, we could find the webdriver from the following folders:
据我所知,当我们通过 DISM 安装 Microsoft Edge webdriver 时,默认情况下,我们可以从以下文件夹中找到 webdriver:
"C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe"
and和
"C:\\Windows\\System32\\MicrosoftWebDriver.exe",
You could check it and try to use this path in your code.您可以检查它并尝试在您的代码中使用此路径。
This error message...这个错误信息...
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, '一个现有的连接被远程主机强行关闭', None, 10054, None))
Microsoft Web Driver has stopped working.
Microsoft Web 驱动程序已停止工作。
A problem caused the program to stop working correctly.
一个问题导致程序停止正常工作。 Windows will close the program and notify you if a solution is available.
Windows 将关闭该程序并通知您是否有可用的解决方案。
...implies that the MicrosoftWebDriver was unable to initiate/spawn a new WebBrowser ie Microsoft Edge Browser session. ...暗示MicrosoftWebDriver无法启动/生成新的WebBrowser,即Microsoft Edge 浏览器会话。
This error can occur due to numerous factors and some of the probhable causes and solutions are as follows:出现此错误的原因有很多,一些可能的原因和解决方案如下:
You need to pass the absolute path of MicrosoftWebDriver through the key executable_path
in either of the ways:您需要通过以下任一方式通过关键的
executable_path
传递MicrosoftWebDriver的绝对路径:
Within double quotes, escaping the back slashes:在双引号内,转义反斜杠:
driver = webdriver.Edge(executable_path="C://Users//username//webdrivers//MicrosoftWebDriver.exe")
Within single quotes and front slashes, preceeded with the raw ( r
) switch:在单引号和前斜杠内,以原始 (
r
) 开关开头:
driver = webdriver.Edge(executable_path=r'C:\\Users\\username\\webdrivers\\MicrosoftWebDriver.exe')
This error is also observed when there is incompatibility between the version of the binaries you are using interms of Selenium client version, WebDriver variant version and Web Browser version.当您使用的二进制文件版本与Selenium客户端版本、 WebDriver变体版本和Web 浏览器版本不兼容时,也会出现此错误。 See Details .
查看详情。
EdgeHTML 18 includes the following new and updated features shipped in the current release of the Microsoft Edge platform, as of the Windows 10 October 2018 Update (10/2018, Build 17763).
截至 2018 年 10 月 10 日的Windows 更新(10/2018,内部版本 17763),EdgeHTML 18 包括以下 Microsoft Edge 平台当前版本中提供的新功能和更新功能。 For changes in specific Windows Insider Preview builds, see the Microsoft Edge Changelog and What's New in EdgeHTML .
有关特定Windows Insider Preview 版本的更改,请参阅Microsoft Edge 更改日志和EdgeHTML 中的新增功能。
Ensure that:确保这件事:
Enable Developer Mode which will install the appropriate version of WebDriver.启用开发人员模式,这将安装适当版本的 WebDriver。
Open Settings app > Go to Update & Security > For Developer and then select "Developer Mode".
You can also install a standalone version of WebDriver in one of two ways:您还可以通过以下两种方式之一安装独立版本的 WebDriver:
Install via DISM by running the following command in an elevated command prompt:通过在提升的命令提示符中运行以下命令,通过 DISM 进行安装:
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Note : When installing MicrosoftWebDriver through the DISM
command, by default the webdriver is installed within the following sub-directories:注意:通过
DISM
命令安装MicrosoftWebDriver 时,默认情况下 webdriver 安装在以下子目录中:
64 bit: 64 位:
C:\\\\Windows\\\\SysWOW64\\\\MicrosoftWebDriver.exe
32 bit: 32 位:
C:\\\\Windows\\\\System32\\\\MicrosoftWebDriver.exe
You can find a couple of relevant discussions in:您可以在以下位置找到一些相关讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.