Python3&selenium raise Message: Can not connect to the Service geckodriver
Asked Answered
D

2

8

I am trying to install selenium in my PC so I tried these:

    pip install selenium

Then I went to this site to download geckodriver and copied it to /usr/bin .

To test if selenium is working. I ran these code and got an error(after 30sec).

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get('http://www.python.org')
assert 'Python' in driver.title
elem = driver.find_element_by_name('q')
elem.send_keys('pycon')
elem.send_keys(Keys.RETURN)

traceback

Any idea how to solve this? I searched some similar questions but didn't find a solution. I'd appriciate it if someone can provide some infomation.

OS:Ubuntu 16.04
Firefox:55
python:3.5
selenium:3.4

Problem solved! Thanks for your help guys.

Solution: make sure there is 127.0.0.1 localhost in the file /etc/host

It turns out that I changed the file for fun a long time ago and forgot to change it back T_T. After I added the 127.0.0.1 localhost , everything is fine.

Dowell answered 23/8, 2017 at 15:15 Comment(2)
Try moving the geckodriver to the folder where your python script is.Caulk
Great.. your solution helped meBarilla
V
1

Solution: make sure there is 127.0.0.1 localhost in the file /etc/host

It works for me perfectly!

Volcanism answered 5/1, 2022 at 20:29 Comment(3)
Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. - From ReviewCordage
ok, I've got itVolcanism
Can anyone explain why 127.0.0.1 localhost lack in /etc/hosts has such an effect?Kauffmann
E
0

Move the geckodriver to /usr/local/bin. You should avoid touching /usr/bin

Also add executable permission to the same

chmod a+x /usr/local/bin/geckodriver

Then in your terminal use echo $PATH. Make sure /usr/local/bin is a part of it. If it is not then execute below

export PATH=/usr/local/bin:$PATH

Then run your python script. And now it should be able to work

Endometrium answered 23/8, 2017 at 15:28 Comment(4)
I tried experimenting with permissions but got a very specific traceback with "permissions denied" error there..not sure if this is what OP is actually experiencing.Thynne
I tried moving geckodrive to /usr/local/bin first. It's not working. Then I tried moving it to /usr/bin. Sadly, not woking. I am sure geckodrive is executable and both /usr/bin and /usr/local/bin is in the PATHDowell
Which version of gecko driver and which version of Firefox?Endometrium
Version and solution are added to the question. Thank you.Dowell

© 2022 - 2024 — McMap. All rights reserved.