Python Selenium Chrome - Message: unknown error: cannot parse internal JSON template: Line: 1, column: 1, Unexpected token

Python Selenium Chrome - Message: unknown error: cannot parse internal JSON template: Line: 1, column: 1, Unexpected token

此代码适用于两台电脑,但在另一台电脑上会引发错误。

webdriver_path: str = os.environ.get("WEBDRIVER_PATH")
chrome_user_data_dir: str = os.environ.get("CHROME_USER_DATA_PATH")
chrome_profile_dir: str = os.environ.get("CHROME_PROFILE_DIR")
options: webdriver.ChromeOptions = webdriver.ChromeOptions()
options.add_argument(f"user-data-dir={chrome_user_data_dir}")
options.add_argument(f"profile-directory={chrome_profile_dir}")
driver: webdriver.Chrome = webdriver.Chrome(executable_path=webdriver_path, options=options)

我收到以下错误:

 File "C:\Users\Pavel\Desktop\Saka-Automation\etsy_create_listing.py", line 100, in <module>
    main()
  File "C:\Users\Pavel\Desktop\Saka-Automation\etsy_create_listing.py", line 27, in main
    driver: webdriver.Chrome = webdriver.Chrome(executable_path=webdriver_path, options=options)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot parse internal JSON template: Line: 1, column: 1, Unexpected token.

我看到问了同样的问题,但很少有答案没有解决问题。尝试删除 chrome 用户配置文件目录中的 /Preferences 和 /Local State。尝试重新安装 chrome 和 chrome 网络驱动程序。尝试使用不同的硒版本。目前似乎没有任何效果。

您针对此问题使用的任何想法或解决方案都将非常有帮助。提前致谢。

我设法把它弄起来,然后又 运行ning 了!对我有用的解决方案是删除 C:\Users\USER\AppData\Local\Google\Chrome 文件夹并重新安装 Chrome。如果您 运行 遇到这个问题,请尝试一下。