You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Appium Python中的RemoteDisconnected连接中止错误

环境

  • Windows 10
  • Python 3.10
  • Appium-Python-Client==2.6.0
  • Appium Server Desktop 1.21.0
  • Electron 7.2.4
  • Node.js 12.8.1

问题

尝试用Python+Appium在Android真机上启动应用时,抛出错误:

('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

脚本代码如下:

def Initialisation_Driver(p_udid, p_systemPort, p_deviceName, p_version, p_os):
    # ======================== INITIALISATION OF DRIVER ================================
    logger.info(
        f"{p_udid}|||============== INITIALISATION OF DRIVER for Smartphone {p_udid} for action Tiktok =========="
    )
    logger.info(f"{p_udid}|||p_udid : {p_udid}")
    logger.info(f"{p_udid}|||p_systemPort : {p_systemPort}")
    logger.info(f"{p_udid}|||p_deviceName : {p_deviceName}")
    logger.info(f"{p_udid}|||p_version : {p_version}")
    logger.info(f"{p_udid}|||p_os : {p_os}")
    logger.info(
        f"{p_udid}|||==============================================================================================="
    )

    desired_caps = {}
    desired_caps['automationName'] = 'UiAutomator2'

    desired_caps['platformName'] = p_os
    desired_caps['platformVersion'] = p_version
    desired_caps['deviceName'] = p_deviceName
    desired_caps['udid'] = p_udid
    desired_caps['noReset'] = 'true'
    desired_caps['systemPort'] = p_systemPort
    desired_caps['chromeDriverPort'] = p_systemPort
    desired_caps['appWaitDuration'] = 100000
    desired_caps['newCommandTimeout'] = 0
    desired_caps['wdaStartupRetries'] = 4
    desired_caps['wdaStartupRetryInterval'] = 20000
    desired_caps['uiautomator2ServerLaunchTimeout'] = 100000
    desired_caps['uiautomator2ServerInstallTimeout'] = 100000
    desired_caps['remoteAppsCacheLimit'] = 0
    desired_caps['waitForQuiescence'] = 'false'
    desired_caps['appPackage'] = 'com.zhiliaoapp.musically'
    desired_caps['appActivity'] = 'com.ss.android.ugc.aweme.main.MainActivity'
    cpt_appium_start=0
    while True:
        try:
            p_driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
            print(f"desired_caps['appPackage'] : {desired_caps['appPackage']}")
            print(f"desired_caps['appActivity'] : {desired_caps['appActivity']}")
            # p_driver.update_settings({"normalizeTagNames": True})
            time.sleep(random.uniform(3.5, 5.3))
            return p_driver

        except Exception as ex:
            cpt_appium_start+=1
            logger.critical(f"{p_udid}|||Something went wrong when initializing p_driver : {ex}")


p_udid = "E531XE1ZM11302266"
p_systemPort = 4723
p_deviceName="BV5500S_EEA"
p_os="Android"
p_version="10.0"


p_driver = Initialisation_Driver(p_udid, p_systemPort, p_deviceName, p_version, p_os)

Appium Desktop无任何响应,服务器日志仅显示启动信息,无脚本通信记录:

[info] [35m[Appium][39m Welcome to Appium v1.21.0
[info] [35m[Appium][39m Non-default server args:
[info] [35m[Appium][39m   relaxedSecurityEnabled: true
[info] [35m[Appium][39m   allowInsecure: {
[info] [35m[Appium][39m   }
[info] [35m[Appium][39m   denyInsecure: {
[info] [35m[Appium][39m   }
[info] [35m[Appium][39m Appium REST http interface listener started on 0.0.0.0:4723

该功能之前正常运行,现在突然失效,脚本与Appium服务器无任何通信。

排查与解决办法

1. 端口冲突问题

你的systemPort和chromeDriverPort都设为4723,而这个端口正是Appium服务器本身监听的端口,直接导致端口占用冲突,阻断通信。

  • 解决:把systemPort和chromeDriverPort改为其他未被占用的端口,比如4724、4725这类,确保和Appium主端口4723不重复。

2. 版本兼容性问题

你使用的Appium-Python-Client是2.6.0,但Appium Server是1.21.0,版本差距过大,存在API不兼容问题。

  • 解决:要么降级Appium-Python-Client到和1.21.0匹配的版本(比如1.3.0左右),要么升级Appium Server到2.x版本(更推荐,2.x是当前主流维护版本)。

3. 设备连接异常

  • 先执行adb devices命令,确认设备E531XE1ZM11302266能被正常识别,无离线状态。
  • 如果设备识别异常,重启adb服务:执行adb kill-server,再执行adb start-server,重新插拔设备后再次检查。

4. 冗余配置干扰

你在Android自动化配置里加入了wdaStartupRetries、wdaStartupRetryInterval这两个iOS专属的WDA配置项,对Android无效,反而可能干扰初始化流程。

  • 解决:删除这两个无用的配置项。

5. 防火墙/代理拦截

Windows防火墙或者代理工具可能拦截了Python脚本与Appium服务器的本地通信。

  • 解决:暂时关闭防火墙测试,或者把Appium和Python脚本加入防火墙白名单;如果使用了代理,确保localhost或127.0.0.1的请求不走代理。

6. Appium进程异常

有时候Appium服务器进程看似正常,但实际已处于僵死状态。

  • 解决:完全关闭Appium Desktop,在任务管理器中结束所有相关的Node.js进程,然后重新启动Appium服务器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 01:35:20