Hello I'm trying to write this algorithm in sage:

def roots(f, q):

# return list of roots of f in finite field of q elements

K.<t> = GF(q)

r = [ ]

g = qq2zz(f).change_ring(K)

for a in K:

if g(a) == 0:

r.append(a)

return r

but i get error, it says that:

Traceback (click to the left of this block for traceback ) ....

how should I correct it?