assert_process_still_running() 和 WebDriverException:消息:服务 geckodriver 在 Raspberry Pi 中使用 SeleniumPython 意外退出错误
由于这个问题,我有点沮丧,并且已经完全重新安装了我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的错误(除了状态代码为 -6 之外,同样的错误),但就我而言,这是因为我使用的是已弃用的浏览器驱动程序初始化(直接向 webdriver 提供可执行路径,而不是向其传递 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:
Use:
See https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/#4-hard-coded-location
Hope that might help you or someone else.
此错误消息...
...暗示有 僵尸进程 GeckoDriver 仍然占用您的系统内存。
解决方案
始终在
tearDown(){}
方法中调用driver.quit()
来关闭&优雅地销毁 WebDriver 和 Web Client 实例,以避免悬空的流程实例。您可以在以下位置
找到一些相关的详细讨论:
This error message...
...implies that there are Zombie process of GeckoDriver still occupying your system memory.
Solution
Always invoke
driver.quit()
withintearDown(){}
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: