How to properly interpolate curve points?

Hi, I’ve been modifying this script for a couple days & can’t figure out how to distribute cubes along a curve. It works great on curves with 2 points, but what if the curve has more points?

It’s more like a ‘resample’ so keeping the overall shape of the curve is a plus

import bpy
from mathutils import geometry

count = 20

# Acquire a reference to the bezier points.
bez_curve =['BezierCurve']
bez_points =[0].bezier_points

# Get a list of points distributed along the curve.
points_on_curve = geometry.interpolate_bezier(

# Create an empty object to serve as parent to all cubes.
bpy.ops.object.empty_add(type='ARROWS', align='WORLD',location=bez_curve.location)

group = bpy.context.active_object = "EMPTY"

empty =['EMPTY']

# Create cubes.
cube_rad = 20 / count
for point in points_on_curve:
    bpy.ops.mesh.primitive_cube_add(size=cube_rad, location=point)
    cube = bpy.context.active_object
    cube.parent = group