FIXED: While upgrading Ubuntu 21.04 to 21.10 firefox (previously installed with apt) got removed and installed with the snap-version. Reversing (uninstalling the snap version & reinstalling with apt) this fixed my issue.
I should've investigated after I had to reset firefox to be the default browser after the dist-upgrade again.
When trying to create a Firefox Webdriver with Selenium for Python I get greeted with the following: "Your Firefox profile cannot be loaded It may be missing or inaccessible." And after clicking 'ok' the following stack trace appears:
>>> foo = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
This has not happened before upgrading to Ubuntu 21.10 (from 21.04) but I do not know what could cause this error. Manually trying to create the driver with the old Geckodriver (0.29.1) does not work too and results in the same error:
$ ./geckodriver.bup -V
geckodriver 0.29.1 (970ef713fe58 2021-04-08 23:34 0200)
The source code of this program is available from
testing/geckodriver in https://hg.mozilla.org/mozilla-central.
This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
$ python3
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> foo = webdriver.Firefox(executable_path=r'./geckodriver.bup')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
The only thing I am positive that changed was the python version (to 3.9.7 from 3.9.5, but using a python-venv with 3.9.5 produces the same errors).
Is there a glaring error I am missing?
Software-Versions/logs:
$ cat geckodriver.log
1635171867200 geckodriver INFO Listening on 127.0.0.1:37079
1635171867204 mozrunner::runner INFO Running command: "/snap/bin/firefox" "--marionette" "-no-remote" "-profile" "/tmp/rust_mozprofileZ5vGbH"
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
amdgpu: os_same_file_description couldn't determine if two DRM fds reference the same file description.
If they do, bad things may happen!
$ geckodriver -V
geckodriver 0.30.0 (d372710b98a6 2021-09-16 10:29 0300)
The source code of this program is available from
testing/geckodriver in https://hg.mozilla.org/mozilla-central.
This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
$ firefox -V
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Mozilla Firefox 93.0
$ pip freeze | grep selenium
selenium==3.141.0
(e: trying with selenium==4.0.0 also did not work)
$ python3 -V
Python 3.9.7
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 21.10"
NAME="Ubuntu"
VERSION_ID="21.10"
VERSION="21.10 (Impish Indri)"
VERSION_CODENAME=impish
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=impish
e2: I suspect the error to be with permissions of the temporary profiles that get created. But the profiles created in '/tmp/' look clean. They are always set to the current user. Specifying them manually with e.g.
foo = webdriver.Firefox(firefox_profile=r'/tmp/rust_mozprofile7nswon')
returns the same error ('Your Firefox profile cannot be loaded. It may be missing or inaccessible.').
CodePudding user response:
Download web driver for firefox : https://github.com/mozilla/geckodriver/releases
then unzip file on default directory
tar -C /usr/local/bin/ -xvf geckodriver-v0.30.0-linux64.tar.gz
Add the chosen geckodriver directory to PATH
export PATH=$PATH:/YourDirectory
Create python file main.py
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://google.com/')
run python main.py
Try this way may be help you
CodePudding user response:
tl;dr: Reinstalling firefox (uninstalling the snap package and installing with apt) fixed the problem.
I took SiKings comment to heart and the only answer mentioned "If your Web Browser base version is too old uninstall the Web Browser through Revo Uninstaller and install a recent GA released version of the Web Browser." so I reinstalled firefox which subsequently fixed the problem.
The version did not change:
$ firefox -V
Mozilla Firefox 93.0
I believe this was most likely a permission problem caused by the dist upgrade.