How to connect python script to Software in the loop ?

Code Which I am running:-

from dronekit import *
import socket
import argparse

def sitl_connect(connection_string):
    try:
        vehicle = connect(connection_string, wait_ready = True , heartbeat_timeout=15)
        print("Virtual Copter Ready")
        return vehicle
    #Bad TCP connection
    except socket.error:
         print("No Server Exist!")

    #Bad TTY connection
    except OSError:
         print("No Serial Exist!")

    #API Error
    except APIException:
         print("Timeout!")

    #other error
    except Exception:
         print("Some Other Error!")

parser = argparse.ArgumentParser()
parser.add_argument('--connect')
args = parser.parse_args()

if args.connect:
    print("connection String: {}".format(args.connect))
    connection_string = args.connect
else:
    print("Defaulting to IP: 127.0.0.1:14550")
    connection_string = '1127.0.0.1:14550'

vehicle = sitl_connect(connection_string)

I am getting this error :-

python D.py --connect 127.0.0.1:14550
connection String: 127.0.0.1:14550
Timeout! - ERROR

where D.py is the above python code.

I am getting API EXCEPTION ERROR , CAN SOMEONE HELP ME IN FIXING THIS ?

PLEASE HELP ME IN FIXING THIS ERRORS.

PLEASE CHECK IMAGES FOR ERRORS:

Help me with this.

try using a higher timeout, like 180

I tried timeout 200 , 500 etc but i am getting same error.

Did you try a simple script, with just a connect and extracting information from the drone, to see if it’s connecting at all first?

Ya , I tried that also but it’s not connecting.
Same issue.




Please see these images. When I tried connecting to hello drone example from drone kit python.

It’s shows error.

Ya , I tried that also but it’s not connecting.
Same issue.