assert_process_still_running() 和 WebDriverException:消息:服务 geckodriver 在 Raspberry Pi 中使用 SeleniumPython 意外退出错误

发布于 2025-01-10 05:04:15 字数 3734 浏览 6 评论 0原文

由于这个问题,我有点沮丧,并且已经完全重新安装了我的 Raspberry Pi。我似乎无法让 geckodriver 工作。我收到以下错误消息。

pi@raspberrypi:~ $ python3
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

Geckodriver 版本:

pi@raspberrypi:~ $ geckodriver -v
1645706311333   webdriver::httpapi      DEBUG   Creating routes
1645706311398   geckodriver     DEBUG   Listening on 127.0.0.1:4444

PATH

pi@raspberrypi:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

我当然更新了 raspian。

感谢@unDetected Selenium 的回答。

我在 test.py 中尝试了以下操作,

import os
import psutil

PROCNAME = "geckodriver" # or chromedriver or IEDriverServer
for proc in psutil.process_iter():
    # check whether the process name matches
    if proc.name() == PROCNAME:
            print(PROCNAME)
            proc.kill()

from selenium import webdriver
browser = webdriver.Firefox()

但收到了相同的错误消息:

Traceback (most recent call last):
  File "/home/pi/test.py", line 12, in <module>
    browser = webdriver.Firefox()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

你们知道为什么吗?我该如何解决这个问题?

多谢!

################ 更新

我尝试了以下代码:

import os
import psutil

PROCNAME = "geckodriver" # or chromedriver or IEDriverServer
for proc in psutil.process_iter():
    # check whether the process name matches
    if proc.name() == PROCNAME:
            proc.kill()

from selenium import webdriver
browser = webdriver.Firefox()

结果是相同的。同样的错误。

pi@raspberrypi:~ $ python3 test.py
Traceback (most recent call last):
  File "/home/pi/test.py", line 11, in <module>
    browser = webdriver.Firefox()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

你有什么想法吗?

I am somewhat frustrated and have already completely reinstalled my Raspberry Pi because of this issue. I can't seem to get geckodriver to work. I get the following error message.

pi@raspberrypi:~ $ python3
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

Geckodriver Version:

pi@raspberrypi:~ $ geckodriver -v
1645706311333   webdriver::httpapi      DEBUG   Creating routes
1645706311398   geckodriver     DEBUG   Listening on 127.0.0.1:4444

PATH

pi@raspberrypi:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

I updated raspian of course.

Thanks @undetected Selenium for your answer.

I tried the following with my test.py

import os
import psutil

PROCNAME = "geckodriver" # or chromedriver or IEDriverServer
for proc in psutil.process_iter():
    # check whether the process name matches
    if proc.name() == PROCNAME:
            print(PROCNAME)
            proc.kill()

from selenium import webdriver
browser = webdriver.Firefox()

I'm getting the same error message:

Traceback (most recent call last):
  File "/home/pi/test.py", line 12, in <module>
    browser = webdriver.Firefox()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

Do you guys know why, how can i fix this issue?

Thanks a lot!

#################
UPDATE

I tried the following code:

import os
import psutil

PROCNAME = "geckodriver" # or chromedriver or IEDriverServer
for proc in psutil.process_iter():
    # check whether the process name matches
    if proc.name() == PROCNAME:
            proc.kill()

from selenium import webdriver
browser = webdriver.Firefox()

The result is the same. Same error.

pi@raspberrypi:~ $ python3 test.py
Traceback (most recent call last):
  File "/home/pi/test.py", line 11, in <module>
    browser = webdriver.Firefox()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

Do you have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏雨凉 2025-01-17 05:04:15

我遇到了类似的错误(除了状态代码为 -6 之外,同样的错误),但就我而言,这是因为我使用的是已弃用的浏览器驱动程序初始化(直接向 webdriver 提供可执行路径,而不是向其传递 Service 对象)。

而不是:

from selenium import webdriver

driver = webdriver.Firefox()

使用:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

DRIVER="geckodriver"
service = Service(executable_path=DRIVER)
driver = webdriver.Firefox(service=service)

请参阅 https://www .selenium.dev/documentation/webdriver/getting_started/install_drivers/#4-hard-coded-location

希望这可以帮助您或其他人。

I had a similar error (same error except status code was -6), but in my case it was because I was using the deprecated browser driver initialization (directly giving executable path to webdriver instead of passing it a Service object).

Instead of:

from selenium import webdriver

driver = webdriver.Firefox()

Use:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

DRIVER="geckodriver"
service = Service(executable_path=DRIVER)
driver = webdriver.Firefox(service=service)

See https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/#4-hard-coded-location

Hope that might help you or someone else.

墨洒年华 2025-01-17 05:04:15

此错误消息...

  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

...暗示有 僵尸进程 GeckoDriver 仍然占用您的系统内存。


解决方案

始终在 tearDown(){} 方法中调用 driver.quit() 来关闭&优雅地销毁 WebDriverWeb Client 实例,以避免悬空的流程实例。


您可以在以下位置

找到一些相关的详细讨论:

This error message...

  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 173, in __init__
    self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 1

...implies that there are Zombie process of GeckoDriver still occupying your system memory.


Solution

Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully to avoid the dangling process instances.


References

You can find a couple of relevent detailed discussions in:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文