Selenium调用Firefox webdriver时geckodriver异常退出状态码64问题
geckodriver 状态码64报错解决方案
状态码64本质是geckodriver启动失败,核心排查方向如下:
版本兼容性排查
- Selenium 4.6及以上版本内置驱动自动管理能力,无需手动下载geckodriver,优先执行
pip install --upgrade selenium升级到最新版Selenium后重试,可解决90%以上的版本不匹配问题 - 若使用低版本Selenium,需保证geckodriver版本和本地安装的Firefox浏览器版本完全适配,同时确认下载的geckodriver和操作系统架构匹配(Windows区分32/64位,Mac区分Intel/Apple Silicon架构,架构不匹配会直接触发启动失败)
路径配置排查
- 若系统PATH变量未配置geckodriver所在目录,可手动指定驱动绝对路径调用,示例代码:
from selenium import webdriver from selenium.webdriver.firefox.service import Service # 替换为本地geckodriver的实际绝对路径 s = Service(executable_path="/your/geckodriver/path") driver = webdriver.Firefox(service=s)
- 若Firefox为自定义路径安装,未使用默认安装目录,需手动指定Firefox二进制文件路径,示例代码:
from selenium import webdriver from selenium.webdriver.firefox.options import Options opts = Options() # 替换为本地Firefox可执行文件的实际绝对路径 opts.binary_location = "/your/firefox/binary/path" driver = webdriver.Firefox(options=opts)
系统限制排查
- Mac系统若弹出「geckodriver无法打开,因为无法验证开发者」提示,执行命令
xattr -d com.apple.quarantine /your/geckodriver/path解除安全限制即可 - 避免使用Firefox Nightly测试版,部分测试版本和正式版geckodriver存在兼容问题,替换为正式版Firefox即可解决
内容的提问来源于stack exchange,提问作者Celestin Krajina-Roso
相关产品推荐
相关产品推荐

