Connection_template.py syntax error (not within connection template?)

During the drone programming primer, within the video titled " Function to Connect Python Script to SITL Drone part1," I copied the code shown in the video almost exactly, with only a few changes for my own organization. When I run connection_template.py (using “python connection_template.py --connect 127.0.0.1:14550” within my dronekit directory, it returns the following error:

From my own research I believe this may be a python version error? I’m not entirely sure how it occurred however, as I followed the exact steps laid out in the video.

Here is the “connection_template.py” that I wrote (copied :sweat_smile:) from the video.

#Dependencies below

from dronekit import connect, VehicleMode, LocationGlobalRelative, APIException
import time
import socket
import exceptions
import math
import argparse

#Functions below

def connectUAV():
parser = argparse.ArgumentParser(description=‘commands’)
parser.add_argument(‘–connect’)
args = parser.parse_args()
connection_string = args.connect
vehicle = connect(connection_string,wait_ready=True)

return vehicle

#Exe

vehicle = connectUAV()

Thank you so much for any help you guys may be able to provide!

What is your python version?

Is there one or two single dash marks on this line?
image

1 Like

Although it didn’t copy and past like that (who knows why?), there are two dashes

Python version 2.7.17 is installed
image

What version pymavlink do you show?

pip freeze | grep -i mav

It might be a version issue.

1 Like

pymavlink shows 2.4.39:
image

I am following the link you attached right now, thank you for the help!

Oh my goodness, it worked. I feel a little silly for not checking the next few videos for something like this, but thank you so much!!!

1 Like

If you move over to a pyhon3 installation you won’t have to deal with version issues