Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x SessionNotCreatedException:消息:会话不是从断开连接的服务器创建的:无法连接到使用ChromeDriver 2.45 Chrome v71的渲染器_Python 3.x_Selenium_Google Chrome_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Python 3.x SessionNotCreatedException:消息:会话不是从断开连接的服务器创建的:无法连接到使用ChromeDriver 2.45 Chrome v71的渲染器

Python 3.x SessionNotCreatedException:消息:会话不是从断开连接的服务器创建的:无法连接到使用ChromeDriver 2.45 Chrome v71的渲染器,python-3.x,selenium,google-chrome,selenium-webdriver,selenium-chromedriver,Python 3.x,Selenium,Google Chrome,Selenium Webdriver,Selenium Chromedriver,当我使用Python使用Selenium执行此代码时: from selenium import webdriver from selenium.webdriver.common.by import By import time driver = webdriver.Chrome(executable_path=r'/Users/qa/Documents/Python/chromedriver') 发生错误: Traceback (most recent call last): Fi

当我使用Python使用Selenium执行此代码时:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome(executable_path=r'/Users/qa/Documents/Python/chromedriver')
发生错误:

   Traceback (most recent call last):
  File "/Users/qa/Documents/Python/try.py", line 4, in <module>
    driver = webdriver.Chrome(executable_path=r'/Users/qa/Documents/Python/chromedriver')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=2.44.609545 (c2f88692e98ce7233d2df7c724465ecacfe74df5),platform=Mac OS X 10.13.6 x86_64)
回溯(最近一次呼叫最后一次):
文件“/Users/qa/Documents/Python/try.py”,第4行,在
driver=webdriver.Chrome(可执行文件_path=r'/Users/qa/Documents/Python/chromedriver')
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/selenium/webdriver/chrome/webdriver.py”,第81行,在__
期望的_能力=期望的_能力)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/selenium/webdriver/remote/webdriver.py”,第157行,在__
启动会话(功能、浏览器配置文件)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/selenium/webdriver/remote/webdriver.py”,第252行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/selenium/webdriver/remote/webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.SessionNotCreateException:消息:未创建会话
从已断开连接:无法连接到渲染器
(会话信息:chrome=71.0.3578.98)
(驱动程序信息:chromedriver=2.44.609545(c2f88692e98ce7233d2df7c724465ecacfe74df5),平台=Mac OS X 10.13.6 x8664)
有人能帮我吗?谢谢。

此错误消息

selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
…意味着ChromeDriver无法启动/生成新的网络浏览器,即Chrome浏览器会话

你需要考虑一个事实:

  • 当您使用Mac OS X时,密钥
    可执行_路径
    必须支持以下值:

  • 因此,这条线将是:

    driver = webdriver.Chrome(executable_path='/Users/qa/Documents/Python/chromedriver')
    
注意:路径本身是原始路径,因此不需要添加开关
r
,然后将其删除

此外,请确保系统上的
/etc/hosts
包含以下条目:

127.0.0.1 localhost.localdomain localhost
#or
127.0.0.1 localhost loopback

我在Windows10机器上遇到了同样的问题。我要做的是打开任务管理器,退出所有Python.exe进程以及所有Chrome.exe进程。在这样做之后,

在linux上遇到了同样的问题,特别是raspberry pi 4(即arm cpu)。我使用了chromium浏览器和chromium chromedriver包

这是我的代码:

browser=Chrome(可执行文件路径='/usr/bin/chromedriver',options=opts)

这是错误消息:

文件“/usr/lib/python3.8/runpy.py”,第194行,在运行模块中作为主模块
返回运行代码(代码、主全局、无、,
文件“/usr/lib/python3.8/runpy.py”,第87行,在运行代码中
exec(代码、运行\全局)
文件“/home/ubuntu/Documents/reliant scrap/reliant_scrap.py”,第296行,在
输出=登录(配置['headless']、配置['download']、配置['site']、配置['creds'])
文件“/home/ubuntu/Documents/reliant scrap/reliant_scrap.py”,第75行,登录
browser=Chrome(可执行文件路径='/usr/bin/chromedriver',options=opts)
文件“/home/ubuntu/.local/lib/python3.8/site packages/selenium/webdriver/chrome/webdriver.py”,第76行,在__
RemoteWebDriver.\uuu init__(
文件“/home/ubuntu/.local/lib/python3.8/site packages/selenium/webdriver/remote/webdriver.py”,第157行,在__
启动会话(功能、浏览器配置文件)
文件“/home/ubuntu/.local/lib/python3.8/site packages/selenium/webdriver/remote/webdriver.py”,第252行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“/home/ubuntu/.local/lib/python3.8/site packages/selenium/webdriver/remote/webdriver.py”,第321行,在execute中
self.error\u handler.check\u响应(响应)
文件“/home/ubuntu/.local/lib/python3.8/site packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.SessionNotCreateException:消息:未创建会话
从已断开连接:无法连接到渲染器
(会话信息:无头镀铬=88.0.4324.150)

但是,当我单独运行
chromedriver
时,它工作正常?我也将该行添加到了
/etc/hosts
,但这没有帮助。

我遇到了类似的错误,首先得到了错误消息:

selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:正常退出。 (未知错误:DevToolsActivePort文件不存在)

通过添加
选项解决了这个问题。将_参数(“--remote debugging port=9230”)
添加到ChromeOptions()。程序运行一次,我得到了与上面相同的错误消息:

selenium.common.exceptions.SessionNotCreateException:消息:未创建会话 从已断开连接:无法连接到渲染器 (会话信息:无头镀铬=89.0.4389.114)

这里的问题是chrome进程没有在程序中正确关闭,因此进程在调试端口上仍然处于活动状态。要解决此问题,请关闭活动端口
sudo kill-9$(sudo lsof-t-i:9230)
,并在代码末尾添加以下行:

driver.stop_client()
driver.close()
driver.quit()

由于我在任何地方都找不到这个答案,我希望它能帮助别人。

用错误跟踪日志更新问题。我使用mac high sierra,我已经尝试使用2.44和2.43,它们也支持Chrome v71。我仍然有一个错误,先生。我在删除可执行文件路径参数时出错。“chromedriver”可执行文件需要在PAT中H.@DebanjanBI正在寻找错误堆栈trace@DebanjanB对不起,先生,我有
driver.stop_client()
driver.close()
driver.quit()