Python selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用ChromeDriver Chrome selenium创建Chrome进程错误

Python selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用ChromeDriver Chrome selenium创建Chrome进程错误,python,selenium,google-chrome,selenium-webdriver,selenium-chromedriver,Python,Selenium,Google Chrome,Selenium Webdriver,Selenium Chromedriver,我试图用webdriver编写基本的python-Google-Chrome交互代码,但在尝试在浏览器上启动链接时,我经常会遇到相同的错误 这是我的密码: from selenium import webdriver import os class Instagrambot: def __init__(self, username, password): self.username = username self.password = password

我试图用webdriver编写基本的python-Google-Chrome交互代码,但在尝试在浏览器上启动链接时,我经常会遇到相同的错误

这是我的密码:

from selenium import webdriver
import os

class Instagrambot:
    def __init__(self, username, password):
        self.username = username
        self.password = password

        self.driver = webdriver.Chrome('./chromedriver.exe')


if __name__ == '__main__':
    ig_bot = Instagrambot('temp_username', 'temp_password')
我在当前目录中有chromedriver,并且我正在为我的浏览器(Chrome79.0.3945.88)使用chromedriver(79.0.3945.36)的正确版本。我得到的全部错误是:

Traceback (most recent call last):
  File "c:/Users/Arthur/Documents/instabot/bot.py", line 16, in <module>
    ig_bot = Instagrambot('temp_username', 'temp_password')
  File "c:/Users/Arthur/Documents/instabot/bot.py", line 12, in __init__
    self.driver = webdriver.Chrome('./chromedriver.exe')
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__desired_capabilities=desired_capabilities)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__self.start_session(capabilities, browser_profile)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response 
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.
回溯(最近一次呼叫最后一次):
文件“c:/Users/Arthur/Documents/instabot/bot.py”,第16行,在
ig_bot=Instagrambot(“临时用户名”、“临时密码”)
文件“c:/Users/Arthur/Documents/instabot/bot.py”,第12行,在__
self.driver=webdriver.Chrome('./chromedriver.exe')
文件“C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\chrome\webdriver.py”,第81行,在\uuuuuu init\uuuuu所需\u功能=所需\u功能中)
文件“C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第157行,在启动会话(功能,浏览器配置文件)
文件“C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第252行,在start\u session response=self.execute(Command.NEW\u session,参数)
文件“C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“C:\Users\Arthur\AppData\Local\Programs\Python\Python37-32\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:未知错误:无法创建Chrome进程。
我已经试过:

将完整的可执行路径写入chromedriver.exe(与bot.py的文件夹相同)

覆盖此答案中建议的Chrome二进制位置:

如果有人能帮助我或给我任何关于如何修复它的见解,我将非常高兴

此错误消息

selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.
…意味着ChromeDriver无法启动/生成新的浏览上下文,即Chrome浏览器会话

我在您的代码块中没有看到任何这样的问题。然而,关于您的测试环境,关于您正在使用的二进制文件版本和用户类型的更多细节将有助于我们更好地调试这个问题。但是,您很可能是以管理员身份执行测试


拇指尺 Chrome在启动过程中崩溃的一个常见原因是,在Linux上以root用户(
管理员)身份运行Chrome。虽然可以通过在创建WebDriver会话时传递
--no sandbox
标志来解决此问题,但这样的配置不受支持,并且非常不推荐。您需要将您的环境配置为以普通用户身份运行Chrome


其他考虑事项 确保:

  • 硒被提升到当前水平
  • ChromeDriver已更新到当前级别
  • Chrome更新到当前的Chrome 79.0版本。(根据)
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
,驱动程序必须是认证版本,我之前也遇到过这个问题。