I cannot access to SITL Drone in Gazebo from Python Script

I am currently programming a drone using Python and the DroneKit library.
For simulation purposes, I have installed SITL and Gazebo following the instructions provided here:

Using SITL with Gazebo
https://ardupilot.org/dev/docs/sitl-with-gazebo.html#using-sitl-with-gazebo

While I was able to set up the simulation successfully, I am encountering an issue where my Python script cannot access the virtual drone within Gazebo.

Are there any additional steps I need to take to enable access from Python?

#############DEPENDENCIES#######################

takeoff_and_landing.py

from dronekit import connect, VehicleMode,LocationGlobalRelative,APIException
import time
import socket

For python3 we should delete “import exceptions”

import math

##############FUNCTIONS##########################

##Function to arm the drone props and takeoff at targetHeight (m)#

def arm_and_takeoff(targetHeight):

while vehicle.is_armable!=True:
	print("Waiting for vehicle to become armable.")
	time.sleep(1)
print("Vehicle is now armable")

vehicle.mode = VehicleMode("GUIDED")

while vehicle.mode!='GUIDED':
	print("Waiting for drone to enter GUIDED flight mode")
	time.sleep(1)
print("Vehicle now in GUIDED MODE. Have fun!!")

vehicle.armed = True
while vehicle.armed==False:
	print("Waiting for vehicle to become armed.")
	time.sleep(1)
print("Look out! Virtual props are spinning!!")

vehicle.simple_takeoff(targetHeight)

while True:
	print("Current Altitude: %d"%vehicle.location.global_relative_frame.alt)
	if vehicle.location.global_relative_frame.alt>=.95*targetHeight:
		break
	time.sleep(1)
print("Target altitude reached!!")

return None

############MAIN EXECUTABLE#############

####sim_vehicle.py opens up port on localhost:14550

vehicle = connect(‘127.0.0.1:14550’,wait_ready=True)

####Arm the drone and takeoff into the air at 5 meters

arm_and_takeoff(5)
print(“Vehicle reached target altitude”)

####Once drone reaches target altitude, change mode to LAND

vehicle.mode=VehicleMode(‘LAND’)
while vehicle.mode!=‘LAND’:
print(“Waiting for drone to enter LAND mode”)
time.sleep(1)
print(“Vehicle now in LAND mode. Will touch ground shortly.”)
#######################################################################

Hi @NK-12MPM, is the SITL instance running as well (can’t tell from the screen shot)? There should be a terminal with mavproxy running (and the mavproxy console as well if using --console with sim_vehicle.py).

The Python script is reporting that there is no link to the vehicle at 127.0.0.1:14550 which is set as a default --out in sim_vehicle.py`, which suggests that SITL is not running properly.