The referenced example code is correct, so I think you must have copied the code incorrectly?
stime = getTime()
while getTime()-stime < 2.0:
for e in tracker.getEvents():
print(e)
There are a set of python examples in the psychopy/demos/coder/iohub/eyetracking
folder that might be of help.