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

This code works on two PCs but throws an error on another one.

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)

I get the following error:

 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.

I saw the same question asked with very few answers that didn't solve the problem. Tried deleting /Preferences and /Local State in the chrome user profile directory. Tried reinstalling chrome and chrome webdriver. Tried with different selenium versions. Nothing seems to work for now.

Any ideas or solutions that you used for this problem would be very helpful. Thanks in advance.



Solution 1:[1]

I managed to get it up and running again! The solution that worked for me was deleting C:\Users\USER\AppData\Local\Google\Chrome folder and reinstalling Chrome. If you run into this problem, give it a try.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Codearts