コンテンツへスキップ

code: 11001, kind: Uncategorized, message: “そのようなホストは不明です。”

わかっている人には「そりゃそうでしょ。」みたいな内容かも^^;

オフラインでselenium を動かす時にWEBDriver の初期化が失敗する。

オフラインでWEBDriver を使用してスクレイピングする際に、自動化のブラウザが「https://chromedriver.storage.googleapis.com/***」にアクセスしようと試みてエラーになる。

初回のみオンラインにしてURL にアクセスすれば、以降はオフラインでも起動する。

環境

Jupyter notebook を使用しています。

エラーの内容

プロンプトに出ているエラーメッセージ

Error: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("chromedriver.storage.googleapis.com")), port: None, path: "/LATEST_RELEASE_107", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError("dns error", Os { code: 11001, kind: Uncategorized, message: "そのようなホストは不明です。" })) }
[I 2022-11-22 14:03:24.920 ServerApp] Saving file at /preference.ipynb
[W 2022-11-22 14:03:24.923 ServerApp] Notebook preference.ipynb is not trusted

Jupyter Notebook に出るエラーメッセージ

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\common\service.py:97, in Service.start(self)
     96 try:
---> 97     path = SeleniumManager.driver_location(browser)
     98 except WebDriverException as new_err:

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\common\selenium_manager.py:68, in SeleniumManager.driver_location(browser)
     67 args = (str(SeleniumManager.get_binary()), "--browser", browser)
---> 68 result = SeleniumManager.run(args)
     69 command = result.split("\t")[-1].strip()

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\common\selenium_manager.py:85, in SeleniumManager.run(args)
     84 if not re.match("^INFO\t", result):
---> 85     raise WebDriverException(f"Unsuccessful command executed: {args}")
     87 return result

WebDriverException: Message: Unsuccessful command executed: ('C:\\Users\\Administrator\\AppData\\Roaming\\python_embed\\python_embed\\python\\python311\\Lib\\site-packages\\selenium\\webdriver\\common\\windows\\selenium-manager.exe', '--browser', 'chrome')


During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
Cell In [4], line 1
----> 1 test=webdriver.Chrome()

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py:81, in WebDriver.__init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
     78 if not service:
     79     service = Service(executable_path, port, service_args, service_log_path)
---> 81 super().__init__(
     82     DesiredCapabilities.CHROME["browserName"],
     83     "goog",
     84     port,
     85     options,
     86     service_args,
     87     desired_capabilities,
     88     service_log_path,
     89     service,
     90     keep_alive,
     91 )

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py:103, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
    100     raise AttributeError("service cannot be None")
    102 self.service = service
--> 103 self.service.start()
    105 try:
    106     super().__init__(
    107         command_executor=ChromiumRemoteConnection(
    108             remote_server_addr=self.service.service_url,
   (...)
    114         options=options,
    115     )

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\common\service.py:100, in Service.start(self)
     98         except WebDriverException as new_err:
     99             logger.debug("Unable to obtain driver using Selenium Manager: " + new_err.msg)
--> 100             raise err
    102         self._start_process(path)
    104 count = 0

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\common\service.py:91, in Service.start(self)
     83 """
     84 Starts the Service.
     85 
   (...)
     88    or when it can't connect to the service
     89 """
     90 try:
---> 91     self._start_process(self.path)
     92 except WebDriverException as err:
     93     if "executable needs to be in PATH" in err.msg:

File ~\AppData\Roaming\python_embed\python_embed\python\python311\Lib\site-packages\selenium\webdriver\common\service.py:203, in Service._start_process(self, path)
    201 except OSError as err:
    202     if err.errno == errno.ENOENT:
--> 203         raise WebDriverException(
    204             f"'{os.path.basename(self.path)}' executable needs to be in PATH. {self.start_error_message}"
    205         )
    206     elif err.errno == errno.EACCES:
    207         raise WebDriverException(
    208             f"'{os.path.basename(self.path)}' executable may have wrong permissions. {self.start_error_message}"
    209         )

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

原因 と解決

PATH の設定ミス。
「chromiumdrive.exe」に直接パス指定するとこの問題が起きる。

誤)set PATH=%PATH%;%cwdirpath%chromedriver_win32\chromedriver.exe

正)set PATH=%PATH%;%cwdirpath%chromedriver_win32\

つまりメッセージ「WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. 」がすごい適切だったと。

パスは問題ないと思っていたので、ハマりました。

以上です。

(Visited 3 times, 1 visits today)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です