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

倾然丶 夕夏残阳落幕 提交于 2019-11-26 17:52:34

问题


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

回答1:


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')



回答2:


This may be answer to this issue,
when it shows something like, Your Firefox profile cannot be loaded. It may be missing or inaccessible.
Actual problem is, Firefox 48.0 or greater not works with selenium 3.0.0 or greater version.
so please check your versions. so, to make it work you need to update with recent selenium and respective geckodriver version too that fixes this issue.

then try basic commands,

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

driver = webdriver.Firefox() 


来源:https://stackoverflow.com/questions/52808760/oserror-errno-8-exec-format-error-with-geckodriver-and-selenium-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!