How to fix ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) in Appium Python?

Environment:

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

Problem:
I try to open an App on a real Android device with Python and Appium and I get this error message:

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

Here is my code:

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)

In the Appium Desktop interface, nothing is happening. Here is the Appium server log:

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

So as you can see, nothing happened. It looks like no communication at all between my script and the Appium server.

It use to work fine and then it doesn’t work anymore. Does anyone have any idea what I am doing wrong?

ok. I fixed it. There are 2 ways to fix this issue:

  1. You reboot your computer.

But this method is too slow. So when it happened a second time to me,

  1. I just unplug the smartphone from my USB port and it worked again.