Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
650 views
in Technique[技术] by (71.8m points)

python - OSError: [Errno 8] Exec format error with GeckoDriver and Selenium on MacOS

I am using firefox gecko driver to make a bot, I keep getting error messages with my bot and I have found that the source of the message is the:

from selenium import webdriver

browser= webdriver.Firefox()

lines.

I have added every file mentioned in the error message to path including gecko driver, firefox, and the other smaller documents. I am at a complete loss

Here is the error message:

Traceback (most recent call last):
  File "/usr/local/bin/fuckobot1.py", line 3, in <module>
    browser= webdriver.Firefox()

File "/Users/'myname'/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()

File "/Users/'myname'/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child

raise child_exception
OSError: [Errno 8] Exec format error
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This error message...

OSError: [Errno 8] Exec format error

...implies that the GeckoDriver binary which was invoked was not in proper format.

Your main issue is the incompatibility of the GeckoDriver binary format with respect to the underlying Operating System.

As you are on MacOS you need to download geckodriver-v0.23.0-macos.tar.gz from mozilla/geckodriver, untar/unzip it and provide the absolute path of the GeckoDriver through the argument executable_path as follows:

from selenium import webdriver

browser= webdriver.Firefox(executable_path='/path/to/geckodriver')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...