Inconsistent ethernet connection

I am trying to control a drone using MAVSDK, and to test its functionality, I have been trying to run the example takeoff and landing script. I modified the script to reflect the fact that my onboard computer is connected to my Pixhawk 6X FC via ethernet cable by changing the line

await drone.connect(system_address="udp://:14540")


await drone.connect(system_address="udp://")

since the IP address of the Pixhawk is set to, and the UDP port is 14540 as per the instructions in the PX4 ethernet setup. However, the connection is pretty unreliable; the drone successfully connects maybe once out of every 10 or 20 times that I run the script. Does anyone know why this may be happening or any tips to make the connection more reliable?