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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Failed to set preferences: unknown error when specify a profile. #14652

Open
heckad opened this issue Oct 25, 2024 · 7 comments
Open

Comments

@heckad
Copy link

heckad commented Oct 25, 2024

What happened?

Expected Behavior -
Firefox run withprovided profile

Actual Behavior -
Firefox is not running

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument("--profile D:\\path\\to\\profile\\dir")
driver = webdriver.Firefox(options=firefox_options)

Python's traceback

Traceback (most recent call last):
  File "/app/tmp/t.py", line 24, in <module>
    driver = webdriver.Firefox(options=firefox_options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/firefox/webdriver.py", line 71, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Failed to set preferences: unknown error

Relevant log output

1729892750450	geckodriver	INFO	Listening on 127.0.0.1:58119
1729892753487	webdriver::server	DEBUG	-> POST /session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts": true, ... .active-protocols": 3}, "args": ["--profile D:\\path\\to\\profile\\dir"]}}}}
1729892753487	geckodriver::capabilities	DEBUG	Trying to read firefox version from ini files
1729892753488	geckodriver::capabilities	DEBUG	Found version 131.0.3
1729892753488	webdriver::server	DEBUG	<- 500 Internal Server Error {"value":{"error":"session not created","message":"Failed to set preferences: unknown error","stacktrace":""}}

Operating System

Windows 11

Selenium version

python 3.12

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

131.0.3

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

GecoDriver 0.35.0

Are you using Selenium Grid?

No response

Copy link

@heckad, 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!

@Delta456
Copy link
Contributor

The given code is incomplete.

@heckad
Copy link
Author

heckad commented Oct 26, 2024

No, that's really all except two imports (Updated messaged to add them and add python's traceback).

@navin772
Copy link
Contributor

Hi @heckad, I was able to reproduce this issue on a Windows machine.

Interestingly, this isn't a problem on macOS; the script worked fine, and the required profile was launched.

@Delta456
Copy link
Contributor

Delta456 commented Oct 28, 2024

Hi @heckad! Can you try this?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument(r"--profile D:\\path\\to\\profile\\dir")
driver = webdriver.Firefox(options=firefox_options)

EDIT: This won't fix it, please ignore.

@heckad
Copy link
Author

heckad commented Oct 28, 2024

Yer, in row string mode you can write a path without double slashes.

@heckad
Copy link
Author

heckad commented Oct 28, 2024

I have the same problem on my Linux machine and in Docker too.
Reproducible dockerfile

FROM python:3.12

# Install Firefox
ARG FIREFOX_VERSION=131.0
RUN echo "deb http://deb.debian.org/debian/ unstable main contrib non-free" >> /etc/apt/sources.list.d/debian.list
RUN apt-get update -qqy \
  && apt-get -qqy --no-install-recommends install firefox \
  && rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
  && wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FIREFOX_VERSION/linux-x86_64/en-US/firefox-$FIREFOX_VERSION.tar.bz2 \
  && apt-get -y purge firefox \
  && rm -rf /opt/firefox \
  && tar -C /opt -xjf /tmp/firefox.tar.bz2 \
  && rm /tmp/firefox.tar.bz2 \
  && mv /opt/firefox /opt/firefox-$FIREFOX_VERSION \
  && ln -fs /opt/firefox-$FIREFOX_VERSION/firefox /usr/bin/firefox

RUN pip install selenium

RUN cat <<EOF > main.py
import sys
from pathlib import Path

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

path = Path(__file__).parent / "firefox_profile"

firefox_options = Options()
firefox_options.add_argument(f"--profile {path}")
firefox_options.add_argument("--headless")
firefox_options.log.level = "trace"
driver = webdriver.Firefox(options=firefox_options, service=Service(log_output=sys.stdout))
driver.get("https://google.com")
driver.quit()
EOF

CMD ["python", "main.py"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants