首页 > 解决方案 > Python webdriver远程触发[WinError 10061]无连接

问题描述

Python webdriver.Remote突然触发“WinError 10061 No connection...”错误

嗨,我有一个 python 脚本,它使用 selenium 从网络上抓取一些数据。它已经运行了几个月没有任何问题。当脚本崩溃时,我偶尔会做的一件事是使用 webdriver.Remote 基本上继续在之前打开的浏览器上工作。曾经工作的简单代码行在下面共享:

chrome = webdriver.Remote(command_executor=command_executor_val, desired_capabilities={})

变量“command_executor_val”基本上是一个包含值“ http://127.0.0.1:53463 ”的字符串。大约一周后,这行代码触发了错误信息:

Traceback (most recent call last): 
    chrome = webdriver.Remote(desired_capabilities=DesiredCapabilities().CHROME,  command_executor=command_executor_val)
  File "C:\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 310, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 466, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 528, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "C:\Python\Python36-32\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)
  File "C:\Python\Python36-32\lib\urllib\request.py", line 544, in _open
    '_open', req)
  File "C:\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Python\Python36-32\lib\urllib\request.py", line 1346, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Python\Python36-32\lib\urllib\request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>

我真的不知道为什么会这样。我阅读了Selenium 远程 webdriver 错误(连接被拒绝)使用 HTTP 代理 - PythonPython urllib.request.urlopen() 返回错误 10061?但它们似乎都不是由 webdriver.Remote 触发的。

我不记得在我的机器上安装过任何东西。我有 Windows 和 Chrome 作为默认浏览器。在此先感谢您的任何建议。

标签: pythonselenium

解决方案


推荐阅读