" />
本ページはプロモーションが含まれています。

スポンサーリンク

Selenium

seleniumで chromeを起動したらsessionnotcreatedexceptionが発生したときの対処法

エラー内容&解消方法

% python3 main.py
Traceback (most recent call last):
  File "/Users/noricgeographic/repositories/keyword-crowler/main.py", line 5, in <module>
    driver = webdriver.Chrome()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    super().__init__(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 106, in __init__
    super().__init__(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 109
Current browser version is 108.0.5359.124 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Stacktrace:
0   chromedriver                        0x00000001012487a8 chromedriver + 4896680
1   chromedriver                        0x00000001011c7db3 chromedriver + 4369843
2   chromedriver                        0x0000000100e11a37 chromedriver + 477751
3   chromedriver                        0x0000000100e43519 chromedriver + 681241
4   chromedriver                        0x0000000100e3e27b chromedriver + 660091
5   chromedriver                        0x0000000100e3a5d2 chromedriver + 644562
6   chromedriver                        0x0000000100e85a27 chromedriver + 952871
7   chromedriver                        0x0000000100e7c233 chromedriver + 913971
8   chromedriver                        0x0000000100e4645c chromedriver + 693340
9   chromedriver                        0x0000000100e479de chromedriver + 698846
10  chromedriver                        0x0000000101216ace chromedriver + 4692686
11  chromedriver                        0x000000010121ada1 chromedriver + 4709793
12  chromedriver                        0x000000010121b5aa chromedriver + 4711850
13  chromedriver                        0x000000010122262f chromedriver + 4740655
14  chromedriver                        0x000000010121bcaa chromedriver + 4713642
15  chromedriver                        0x00000001011ef992 chromedriver + 4532626
16  chromedriver                        0x000000010123a3c8 chromedriver + 4838344
17  chromedriver                        0x000000010123a545 chromedriver + 4838725
18  chromedriver                        0x00000001012506ef chromedriver + 4929263
19  libsystem_pthread.dylib             0x00007ff80375d4e1 _pthread_start + 125
20  libsystem_pthread.dylib             0x00007ff803758f6b thread_start + 15

エラー解消方法

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 109
Current browser version is 108.0.5359.124 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

上記メッセージは、
ChromeDriverは109をサポートしているが、
あなたの使ってるChromeは108.0.5359だよと怒っている。

ChromeDriverのバージョンを下げるか、
Chromeのバージョンを上げるかして整合させる必要がある。

バージョンをチェックする

chromedriverのバージョン

% pip3 list                               
Package             Version
------------------- ---------------
async-generator     1.10
attrs               22.2.0
certifi             2022.12.7
chromedriver-binary 109.0.5414.25.0
exceptiongroup      1.1.0

chromeのバージョン

上記のように、chromedriver-binaryとChromeのバージョンが一致していない場合、エラーとなります。

解決できた方法 - chromedriver-binary-autoが未インストールの場合

まず、chromedriverをアンインストールした。

% pip3 uninstall chromedriver-binary

その後、chromedriver-binary-autoというのを入れた。

% pip3 install chromedriver-binary-auto

そしたら動きました。

解決できた方法 - chromedriver-binary-autoがインストール済みの場合

chromedriver-binary-autoがインストール済みの場合、再インストールしましょう。

再インストールしてクローラーを動かすことで、現在のChromeのバージョンに合ったchromedriverを自動でインストールしてくれます。
その結果、クローラーは正常に動いてくれるようになります。

まず、chromedriver-binary-autoをアンインストールします。

% pip3 uninstall chromedriver-binary-auto
Found existing installation: chromedriver-binary-auto 0.2.3
Uninstalling chromedriver-binary-auto-0.2.3:
  Would remove:
    /Library/Frameworks/Python.framework/Versions/3.10/bin/chromedriver-path
    /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/chromedriver_binary/*
    /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/chromedriver_binary_auto-0.2.3-py3.10.egg-info
Proceed (Y/n)? y
  Successfully uninstalled chromedriver-binary-auto-0.2.3

その後、chromedriver-binary-autoをインストールします。

% pip3 install chromedriver-binary-auto  
Collecting chromedriver-binary-auto
  Downloading chromedriver-binary-auto-0.2.5.tar.gz (5.2 kB)
  Preparing metadata (setup.py) ... done
Installing collected packages: chromedriver-binary-auto
  DEPRECATION: chromedriver-binary-auto is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for chromedriver-binary-auto ... done
Successfully installed chromedriver-binary-auto-0.2.5

[notice] A new release of pip is available: 23.0 -> 23.0.1
[notice] To update, run: pip install --upgrade pip

それから、プログラムを動かしてください。

スポンサーリンク

-Selenium