Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: webdriver - Process unexpectedly closed with status 127 (Geckodriver) #11414

Closed
self-dmz opened this issue Dec 12, 2022 · 16 comments

Comments

@self-dmz
Copy link

What happened?

Hi!

Just trying to start working with Geckodriver get the following exception: "selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 127".

Using Chrome driver the code below works fine.

webdriver-manager==3.8.5
selenium==4.7.2

Thanks in advance

How can we reproduce the issue?

# Try to start this script

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager

opts = Options()
opts.log.level = "trace"
opts.add_argument('--headless')

# ------ Process unexpectedly closed with status 127
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))

# ------ Process unexpectedly closed with status 127
#driver = webdriver.Firefox(options=opts, executable_path=GeckoDriverManager().install())
#driver = webdriver.Firefox(executable_path="/media/dmz/HDD/geckodriver/geckodriver")

# ------ Process unexpectedly closed with status 127
#service = FirefoxService(executable_path="/media/dmz/HDD/geckodriver/geckodriver")
#driver = webdriver.Firefox(options=opts, service=service)

driver.get('https://google.com')

print(driver.title)

Relevant log output

[WDM] - Downloading: 19.0kB [00:00, 6.53MB/s]                   
Traceback (most recent call last):
  File "/media/dmz/HDD/RPT/Python/techPanda/debug.py", line 11, in <module>
    driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
  File "/media/dmz/HDD/RPT/Python/techPanda/venv/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 197, in __init__
    super().__init__(command_executor=executor, options=options, keep_alive=True)
  File "/media/dmz/HDD/RPT/Python/techPanda/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "/media/dmz/HDD/RPT/Python/techPanda/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/media/dmz/HDD/RPT/Python/techPanda/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/media/dmz/HDD/RPT/Python/techPanda/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 127

Operating System

Linux Mint 20.3 x86_64; 5.4.0-135-generic

Selenium version

selenium==4.7.2

What are the browser(s) and version(s) where you see this issue?

Browser doesn't start, Firefox version = 107.0.1 (64)

What are the browser driver(s) and version(s) where you see this issue?

geckodriver-v0.32.0-linux64

Are you using Selenium Grid?

NO

@github-actions
Copy link

@self-dmz, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol
Copy link
Member

diemol commented Dec 12, 2022

What happens if you avoid webdriver-manager? Selenium has an embedded manager for drivers (called Selenium Manager) since 4.6.0.

@self-dmz
Copy link
Author

self-dmz commented Dec 12, 2022

`! --- The same exception is got - "Process unexpectedly closed with # status 127"

import time
from selenium import webdriver

driver = webdriver.Firefox() # Message: Process unexpectedly closed with status 127

driver = webdriver.Chrome() # -- works OK !

driver.maximize_window()
driver.get('https://google.com/')
print(driver.title)

time.sleep(3)
driver.quit()`

@symonk
Copy link
Member

symonk commented Dec 12, 2022

@self-dmz can you try the same example with a virtual env that is not residing in /media/ ?

@symonk symonk added the C-py label Dec 12, 2022
@self-dmz
Copy link
Author

I tired with new project created at /home... It fails with the same exception. webdriver.Chrome() works properly. The same script is used.

Traceback (most recent call last):
File "/home/dmz/python/geckoIssue/debug.py", line 4, in
driver = webdriver.Firefox() # Message: Process unexpectedly closed with status 127
File "/home/dmz/python/geckoIssue/venv/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 197, in init
super().init(command_executor=executor, options=options, keep_alive=True)
File "/home/dmz/python/geckoIssue/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 288, in init
self.start_session(capabilities, browser_profile)
File "/home/dmz/python/geckoIssue/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/dmz/python/geckoIssue/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "/home/dmz/python/geckoIssue/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 12

@benxyzzy
Copy link

I got the same error, and a geckodriver.log in the working directory contained lines like

1672176966006	geckodriver	INFO	Listening on 127.0.0.1:38849
/snap/firefox/current/firefox.launcher: 46: exec: /snap/pycharm-professional/314/usr/lib/firefox/firefox: not found
1672176966516	mozrunner::runner	INFO	Running command: "/snap/firefox/current/firefox.launcher" "--marionette" "--remote-debugging-port" "37603" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "/tmp/rust_mozprofileg3ocu3"
/snap/firefox/current/firefox.launcher: 46: exec: /snap/pycharm-professional/314/usr/lib/firefox/firefox: not found

You can see I am using a snap install of PyCharm which seems to be messing up the path to the firefox executable?
This is on Ubuntu 22.04, Python 3.10.6, with selenium==4.7.2 and webdriver-manager==3.8.5 installed in a venv.

(so I ran my code again in a terminal outside PyCharm and got a different error, but I guess that's a different issue):

1672178047545	geckodriver	INFO	Listening on 127.0.0.1:37587
1672178048153	mozrunner::runner	INFO	Running command: "/snap/bin/firefox" "--marionette" "--remote-debugging-port" "40965" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "/tmp/rust_mozprofiletcMcJG"
Gtk-Message: 21:54:08.241: Not loading module "atk-bridge": The functionality is provided by GTK natively. Please try to not load it.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.

plus a nice popup error message window Your Firefox profile cannot be loaded. It may be missing or inaccessible. And the exception message this time is Process unexpectedly closed with status 1

@titusfortner
Copy link
Member

Snap is a pain for selenium. It has its own driver and none of the driver managers support it. You need to explicitly pass on the location to the driver in the service constructor.

@self-dmz are you also using snap?

@benxyzzy
Copy link

Following @titusfortner 's advice and this, the following works for me, within PyCharm and not needing to do anything special regarding Firefox profile locations:

    install_dir = "/snap/firefox/current/usr/lib/firefox"
    driver_loc = os.path.join(install_dir, "geckodriver")
    binary_loc = os.path.join(install_dir, "firefox")

    service = FirefoxService(driver_loc)
    opts = webdriver.FirefoxOptions()
    opts.binary_location = binary_loc
    driver = webdriver.Firefox(service=service, options=opts)

Note that the opts.binary_location is required, not just the driver location.

/snap/firefox/current is a symlink to the current version directory within /snap/firefox, so I'm hoping that is a better way to dynamically keep pointed at the right binary + driver, without the subprocess("find ...") hack in the SO answer

@self-dmz
Copy link
Author

self-dmz commented Dec 28, 2022

Snap is a pain for selenium. It has its own driver and none of the driver managers support it. You need to explicitly pass on the location to the driver in the service constructor.

@self-dmz are you also using snap?

yes, firefox installed via snap. and the scheme described by @benxyzzy also works on my PC.

@self-dmz
Copy link
Author

self-dmz commented Dec 28, 2022

Following @titusfortner 's advice and this, the following works for me, within PyCharm and not needing to do anything special regarding Firefox profile locations:

    install_dir = "/snap/firefox/current/usr/lib/firefox"
    driver_loc = os.path.join(install_dir, "geckodriver")
    binary_loc = os.path.join(install_dir, "firefox")

    service = FirefoxService(driver_loc)
    opts = webdriver.FirefoxOptions()
    opts.binary_location = binary_loc
    driver = webdriver.Firefox(service=service, options=opts)

Note that the opts.binary_location is required, not just the driver location.

/snap/firefox/current is a symlink to the current version directory within /snap/firefox, so I'm hoping that is a better way to dynamically keep pointed at the right binary + driver, without the subprocess("find ...") hack in the SO answer

many thanks, @benxyzzy! the code you provided works in my case.

@AntiPetrun
Copy link

Hi, guys! I have such problem: NameError: name 'FirefoxService' is not defined

@hotenov
Copy link

hotenov commented Mar 6, 2023

@AntiPetrun Hi! Check your imports, because in issue description more common Service was imported as FirefoxService (with other module name)

from selenium.webdriver.firefox.service import Service as FirefoxService

@manel00
Copy link

manel00 commented Jul 11, 2023

Hello, still having the same issue... anyone knows how to fix it? I am using ubuntu 22

@swapnil-uptycs
Copy link

Hello, still having the same issue... anyone knows how to fix it? I am using ubuntu 20

@titusfortner
Copy link
Member

titusfortner commented Sep 14, 2023

As of Selenium 4.11, you don't need to import as for the service classes (https://www.selenium.dev/documentation/webdriver/drivers/service/#default-service-instance)

try:

    install_dir = "/snap/firefox/current/usr/lib/firefox"
    driver_loc = os.path.join(install_dir, "geckodriver")
    binary_loc = os.path.join(install_dir, "firefox")

    service = webdriver.FirefoxService(driver_loc)
    opts = webdriver.FirefoxOptions()
    opts.binary_location = binary_loc
    driver = webdriver.Firefox(service=service, options=opts)

Copy link

github-actions bot commented Dec 5, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants