Import & assign material (Script; "not a str")

Hello everyone,
I am trying to import materials from another blend file and assign the nth material to the active object. I have tried multiple solutions but I always hit errors.

  1. Approach 1
    Here the error is: “list indices must be integers or slices, not str” (in the approach shown below):

with bpy.data.libraries.load(path) as (data_from, data_to):
data_to.materials = data_from.materials
mat = data_to.materials
cnt=0
for m in data_to.materials:
cnt=cnt+1
if (cnt>1):
break

Assign material

obj=bpy.context.scene.objects.active

material1 = data_to.materials[cnt]
obj.active_material = data_to.materials[material1]

  1. Approach 2
    When I try to assign the material by using an index instead the error is: “bpy_struct: item.attr = val: Object.active_material expected a Material type, not str” (in the approach shown below):
    obj.active_material = data_to.materials[cnt]

I guess, I haven’t fully understood what data_from/data_to objects are and how to use them. Can somebody help me here?

Thanks in advance,

Gemor