1

I am trying to launch a python script, containing selenium webdriver usage, over SSH using PuTTY. When running the command "sudo python3.4 [filepath].py" in the SSH terminal the "connection refused" error is raised, but when running the same command on the server terminal it works as it should.

The server is a Raspberry pi running Raspbian and is using geckodriver for the webdriver. The computer connecting to is using SSH is running Windows 10.

I have tried typing "export DISPLAY=:0" before running the python script. I also tried running the command trough gnome-terminal, hoping it would force the pi into loading the gui as I thought that the selenium driver being a graphical one might be part of the problem.

I am very new to SSH:ing and still fairly new to selenium.

To make it simpler than my actual program, this is just a script to launch selenium which still shows the same problem.

from selenium import webdriver

driver = webdriver.Firefox(executable_path=r'/home/pi/Downloads/gecko3/geckodriver')
driver.get('www.google.com')

driver.quit()

The output (coming into my SSH-client) is as follows:

Traceback (most recent call last):
  File "/home/pi/Desktop/webtest.py", line 3, in <module>
    driver = webdriver.Firefox(executable_path=r'/home/pi/Downloads/gecko3/geckodriver')
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

Any help would be greatly appreciated

  • Please check this possible solution [selenium.common.exceptions.WebDriverException: Message: connection refused](https://stackoverflow.com/questions/39547598/selenium-common-exceptions-webdriverexception-message-connection-refused) does it solves your issue? – Xarvalus May 11 '19 at 21:33
  • Avoid Selenium/Python/Firefox combination on ARM, switch to Chrome. Firefox and Geckodriver is mostly buggy. And if you need to build Geckodriver from sources then you are SOL because Rust/Cargo has build errors on ARM. (Speaking from experience. I spent several weeks trying to get Selenium/Python/Firefox to work as expected on ARM. I finally gave up and cutover to Chrome). – jww May 11 '19 at 22:01

1 Answers1

0

I had the exact same issue yesterday and it is related to security. monitor your runtime process for gecodriver/firefox/python and make sure the runtime user is what you expect. in my case it was running as IUSR (IIS), when I changed it to NETWORK_SERVICES it worked fine. This is because it tried to create temp profile in the windows directory. you might have similar issue.

you might also have to create private profile and use it in your code

ffprofile = webdriver.FirefoxProfile(r"C:..\p1s7i6ei.webScraper") WD = webdriver.Firefox(capabilities=ffCap, options=WDOptions, service_log_path=os.devnull, firefox_profile=ffprofile)

https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles

tribs
  • 1