使用Appium mac2驱动时出现500内部服务器错误求助
Appium mac2驱动内部服务器错误(500状态码)解决方案
问题描述
使用Appium mac2驱动连接Mac应用时,webdriver.Remote能正常连接Appium服务器,但服务器返回500状态码。核心报错为:
Mac2Driver server is not listening within 120000ms timeout. Try to increase the value of 'serverStartupTimeout' capability, check the server logs and make sure the xcodebuild host process could be started manually from a terminal
日志同时显示127.0.0.1:10100端口连接被拒绝。
用户代码:
from appium import webdriver from appium.options.common import AppiumOptions # Set up the desired capabilities options = AppiumOptions() options.set_capability("platformName", "mac") options.set_capability("automationName", "mac2") options.set_capability("app", "/System/Applications/Calculator.app") # Create the WebDriver instance (this is where the error happens) driver = webdriver.Remote("http://localhost:4723/wd/hub", options=options)
服务器关键日志片段:
[87a9f913][WD Proxy] connect ECONNREFUSED 127.0.0.1:10100 [87a9f913][AppiumDriver@4271] Encountered internal error running command: Error: Mac2Driver server is not listening within 120000ms timeout. Try to increase the value of 'serverStartupTimeout' capability, check the server logs and make sure the xcodebuild host process could be started manually from a terminal at WDAMacServer.startSession (/Users/dhakalrabi/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:432:17) at processTicksAndRejections (node:internal/process/task_queues:95:5) at Mac2Driver.createSession (/Users/dhakalrabi/.appium/node_modules/appium-mac2-driver/lib/driver.js:120:7) at AppiumDriver.createSession (/opt/homebrew/lib/node_modules/appium/lib/appium.js:731:35) [87a9f913][HTTP] <-- POST /wd/hub/session 500 120052 ms - 964
解决步骤
1. 手动启动WebDriverAgentMac排查基础问题
- 找到mac2驱动的WebDriverAgentMac项目路径,通常为:
~/.appium/node_modules/appium-mac2-driver/node_modules/appium-webdriveragent-mac - 用Xcode打开
WebDriverAgentMac.xcodeproj - 在Xcode中选择你的Mac设备作为运行目标,确保签名配置正确(可使用本地开发者签名或付费开发者账号)
- 点击运行按钮,检查是否能成功启动。如果Xcode报错,优先解决签名、依赖或权限问题。
2. 延长服务器启动超时时间
在capabilities中添加serverStartupTimeout参数,延长超时时间至3分钟(180000毫秒):
options.set_capability("serverStartupTimeout", 180000)
3. 检查并释放端口占用
- 检查10100端口是否被其他进程占用:
lsof -i :10100 - 如果有占用进程,执行以下命令杀掉进程(替换
<PID>为查到的进程ID):kill -9 <PID>
4. 重新安装mac2驱动
- 卸载现有mac2驱动:
appium driver uninstall mac2 - 安装最新版本的mac2驱动:
appium driver install mac2
5. 验证Xcode环境与权限
- 确保Xcode命令行工具已安装:
xcode-select --install - 打开Xcode,同意许可协议,确保能正常运行,避免因权限问题导致xcodebuild无法启动。
6. 启用Appium debug日志排查细节
启动Appium服务器时添加debug级日志参数,获取更详细的启动报错信息:
appium --log-level debug
内容的提问来源于stack exchange,提问作者user23256993
相关产品推荐
相关产品推荐

