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]: Trying to launch Firefox webdriver #10813

Closed
cleconte987 opened this issue Jun 25, 2022 · 15 comments
Closed

[🐛 Bug]: Trying to launch Firefox webdriver #10813

cleconte987 opened this issue Jun 25, 2022 · 15 comments
Labels

Comments

@cleconte987
Copy link

cleconte987 commented Jun 25, 2022

What happened?

I tried to launch Firefox webdriver with python API, to retrieve information on a web page. Previously I was using this code snippet on a Mac and everything was working fine. When switching to Linux I changed the geckodriver binary to be the one for Linux.
But I got this issue where it says it doesn't find the marionette port.
I saw this thread on stackoverflow: https://stackoverflow.com/questions/72374955/failed-to-read-marionette-port-when-running-selenium-geckodriver-firefox-a which I thought might be related to my problem.
So I tried to run the script in super user mode. It didn't change anything

[EDIT]
I installed Ubuntu about 10 days ago from an iso image from ubuntu.com: https://ubuntu.com/download/desktop/thank-you?version=22.04&architecture=amd64 and Firefox was already installed with it.
I downloaded geckodriver from https://github.com/mozilla/geckodriver/releases and copied it in some directory in my project. I also tried to put it at some moment in /usr/bin but it didn't change anything.
I tried right now by changing geckodriver path to be absolute: "/home/clement/Desktop/mobilite-electrique.tech/bin". It did the same result.

The code snippet is the following:

`from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options as FirefoxOptions

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import time


s = Service('../../../bin/geckodriver')
firefox_options = FirefoxOptions()
firefox_options.add_argument("--headless")
driver = webdriver.Firefox(service=s, options = firefox_options)

driver.implicitly_wait(5)
URL = input_url

driver.get(URL)

# wait for the first element matching the passed locator presence.
# We use dot here because we want a class
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '.' + vehicle_base_locator)))

# add a short delay to make all the elements loaded
time.sleep(0.6)`

How can we reproduce the issue?

from selenium import webdriver
	from selenium.webdriver.firefox.service import Service
	from selenium.webdriver.common.by import By
	from selenium.webdriver.firefox.options import Options as FirefoxOptions
	
	from selenium.webdriver.support.ui import WebDriverWait
	from selenium.webdriver.support import expected_conditions as EC

	import time


	s = Service('../../../bin/geckodriver')
	firefox_options = FirefoxOptions()
	firefox_options.add_argument("--headless")
	driver = webdriver.Firefox(service=s, options = firefox_options)

	driver.implicitly_wait(5)
	URL = input_url

	driver.get(URL)

	# wait for the first element matching the passed locator presence.
	# We use dot here because we want a class
	wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '.' + vehicle_base_locator)))

	# add a short delay to make all the elements loaded
	time.sleep(0.6)

Relevant log output

Traceback (most recent call last):
  File "/home/clement/Desktop/mobilite-electrique.tech/Project related information/web_scrapping/web_scraping_scripts/scrap_web.py", line 344, in <module>
    scrap_web_global(*sys.argv[1:])
  File "/home/clement/Desktop/mobilite-electrique.tech/Project related information/web_scrapping/web_scraping_scripts/scrap_web.py", line 247, in scrap_web_global
    driver = webdriver.Firefox(service=s, options = firefox_options)
  File "/home/clement/Desktop/mobilite-electrique.tech/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver.py", line 177, in __init__
    super().__init__(
  File "/home/clement/Desktop/mobilite-electrique.tech/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 277, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/clement/Desktop/mobilite-electrique.tech/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 370, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/clement/Desktop/mobilite-electrique.tech/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
  File "/home/clement/Desktop/mobilite-electrique.tech/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Failed to read marionette port


debug logging is:

`DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:45393/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts": true, "moz:debuggerAddress": true, "pageLoadStrategy": "normal", "moz:firefoxOptions": {"args": ["--headless"]}}}}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:45393
DEBUG:urllib3.connectionpool:http://localhost:45393 "POST /session HTTP/1.1" 500 88
DEBUG:selenium.webdriver.remote.remote_connection:Remote response: status=500 | data={"value":{"error":"timeout","message":"Failed to read marionette port","stacktrace":""}} | headers=HTTPHeaderDict({'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-cache', 'content-length': '88', 'date': 'Mon, 27 Jun 2022 07:45:58 GMT'})
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request`

Operating System

Ubuntu 22.04

Selenium version

4.3.0

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

Firefox 101.0.1 (64 bits)

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

geckodriver v0.31.0 linux 64

Are you using Selenium Grid?

No response

@github-actions
Copy link

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

@symonk
Copy link
Member

symonk commented Jun 26, 2022

Cannot recreate this on ubuntu; how exactly did you install firefox & geckodriver on your system? can you please share the DEBUG logging output from the selenium logger also? You can do this via:

import logging
logging.basicConfig(level=logging.DEBUG)
# <run your script code here>

I would like the see the HTTP request/response logging when trying to create the new session. Passing your geckodriver path like that while in theory should work; can you also try it with an absolute path?

Thanks.

@symonk symonk added the C-py label Jun 26, 2022
@cleconte987
Copy link
Author

I edited my post to add the information you asked. I tried modifying geckodriver to absolute path but didn't change outcome. I installed Ubuntu recently and Firefox was shipped with it. I installed geckodriver from github/mozilla/geckodriver

@sarahmcknz
Copy link

sarahmcknz commented Jun 27, 2022

Same problem here. Ubuntu 22.04, Firefox 101.0.1, geckodriver 0.31.0, selenium 4.3.0. Firefox installed with sudo apt-get install firefox

The code (works under Windows):

import logging
logging.basicConfig(level=logging.DEBUG)

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://lumtest.com/myip.json')
driver.quit()

Log output:

DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:48201/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts": true, "moz:debuggerAddress": true, "pageLoadStrategy": "normal"}}}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:48201
DEBUG:urllib3.connectionpool:http://localhost:48201 "POST /session HTTP/1.1" 500 88
DEBUG:selenium.webdriver.remote.remote_connection:Remote response: status=500 | data={"value":{"error":"timeout","message":"Failed to read marionette port","stacktrace":""}} | headers=HTTPHeaderDict({'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-cache', 'content-length': '88', 'date': 'Mon, 27 Jun 2022 09:57:24 GMT'})
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
Traceback (most recent call last):
File "/home/amid/test_ff.py", line 6, in
driver = webdriver.Firefox()
File "/home/amid/.local/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver.py", line 177, in init
RemoteWebDriver.init(
File "/home/amid/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 275, in init
self.start_session(capabilities, browser_profile)
File "/home/amid/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 365, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/amid/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "/home/amid/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Failed to read marionette port

@symonk
Copy link
Member

symonk commented Jun 27, 2022

Thanks both; could you try installing firefox through different means on ubuntu and see if the problem persists? the 500 coming back is unexpected here and the error quite obscure.

@sarahmcknz
Copy link

Which installation method is recommended for headless Ubuntu VPS (no GUI)?
Firefox seems to be installed:
which firefox
/usr/bin/firefox
firefox -v
Mozilla Firefox 101.0.1

@cleconte987
Copy link
Author

I uninstalled Firefox which was installed through snap. I then installed it through apt. Apt also installed it through snap in the end. I tried to relaunch WebDriver then but it didn't change anything.
However I then desinstalled Firefox that was installed through apt and snap and downloaded a previous version of firefox (100.0.2) that I installed in /opt. I wanted to try if it was the version of Firefox that was causing problems. I symlinked this version in /usr/bin. Tried to run my script and now it works!
After some time Firefox auto updated itself to version 101.0.1 and my script still works!

@symonk
Copy link
Member

symonk commented Jun 27, 2022

from what I can find, it looks like snap related installs are linked to this problem, I will have a look tomorrow if I can understand/pin point why

@cleconte987
Copy link
Author

Ok thank you very much!

@WolfgangFahl
Copy link

seeing this in an automated unit-test case using MacOs. https://github.com/justpy-org/justpy/actions/runs/3053721493/jobs/4924707114

Error in tests.test_ajax.TestAjaxWithSelenium.testAjax
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
    yield
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/asynctest/case.py", line 293, in run
    self._setUp()
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/asynctest/case.py", line 248, in _setUp
    self.loop.run_until_complete(self.setUp())
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/asynctest/case.py", line 224, in wrapper
    return method(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/runner/work/justpy/justpy/tests/test_ajax.py", line 17, in setUp
    await super().setUp(port=8126)
  File "/home/runner/work/justpy/justpy/tests/base_selenium_test.py", line 28, in setUp
    self.browser = SeleniumBrowsers(headless=Basetest.inPublicCI()).getFirst()
  File "/home/runner/work/justpy/justpy/tests/browser_test.py", line 31, in getFirst
    self.getBrowsers()
  File "/home/runner/work/justpy/justpy/tests/browser_test.py", line 43, in getBrowsers
    self.browsers["firefox"] = self._getFirefoxWebDriver()
  File "/home/runner/work/justpy/justpy/tests/browser_test.py", line 54, in _getFirefoxWebDriver
    browser = webdriver.Firefox(options=options)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 177, in __init__
    super().__init__(
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 270, in __init__
    self.start_session(capabilities, browser_profile)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 363, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "/opt/hostedtoolcache/Python/3.8.13/x64/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Failed to read marionette port

@titusfortner
Copy link
Member

Geckodriver has a set list of places it looks for Firefox, perhaps it isn't finding it, or is finding the wrong one. Try explicitly specifying the path of Firefox you want to use with the binary method/property on the options class.

@WolfgangFahl
Copy link

This is not reproducible. Sometimes the tests works and sometimes it doesn't. Since the test configuration stays the same i doubt that the Firefox path is the problem. I assume this is a far more subtle problem.

@titusfortner
Copy link
Member

Looks like there are a number of potential solutions listed here — https://stackoverflow.com/questions/72374955/failed-to-read-marionette-port-when-running-selenium-geckodriver-firefox-a

The error is coming from geckodriver, though, not from Selenium, so underlying issue will need to be addressed with Mozilla.

@titusfortner titusfortner added the G-geckodriver Requires fixes in GeckoDriver label Sep 15, 2022
@github-actions
Copy link

Hi, @cleconte987.
This issue has been determined to require fixes in GeckoDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an Issue with the GeckoDriver team.

Feel free to comment the issues that you raise back in this issue. Thank you.

@github-actions
Copy link

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 Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants