You need to enable JavaScript to run this app. M1 Mac下Python无法连接Docker内Selenium 报错KeyError: 'status'
优惠活动
大模型
产品
解决方案
定价
更多

M1 Mac下Python无法连接Docker内Selenium 报错KeyError: 'status'

问题原因
  • 版本协议不兼容:你部署的Selenium Grid 4.x使用W3C标准响应格式,而本地Python Selenium库为3.x版本,仅支持旧版JSONWP协议,解析响应时无法匹配结构导致KeyError: 'status'
  • 架构兼容性问题:你拉取的selenium/standalone-chrome镜像为amd64架构,在M1 arm64架构设备上通过Docker转译运行,存在潜在兼容隐患
解决步骤
  1. 升级本地Python Selenium库到4.x版本
    执行命令:
    pip install --upgrade selenium

  2. 调整Python连接代码,适配Selenium 4的W3C协议规范
    代码示例:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
driver = webdriver.Remote(
    command_executor="http://localhost:4444/wd/hub",
    options=options
)

driver.get("https://stackoverflow.com/")
print(driver.title)
driver.quit()
  1. (M1设备可选优化)更换为arm64架构适配的Selenium镜像
    停止原有容器后,使用如下命令启动服务:
    docker run -d -p 4444:4444 --shm-size="2g" seleniarm/standalone-chromium:latest

调整完成后重新运行代码即可正常执行。

内容的提问来源于stack exchange,提问作者Ren

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 07:27:03