What causes AttributeError: 'Material' object has no attribute 'texture_slots'? What causes, in the script below, the error given in the title?

if mat.texture_slots[0] == None:
    tex = target_object.material.texture_slots.add()

    tex.texture = bpy.data.texture.new(target_object.name, type='IMAGE')

    tex.texture_coords = 'UV'
# target_object.texture = bpy.ops.texture.new()

    new_image = bpy.data.images.load(image_filename)
Material.texture_slots is only available for blender internal render.

How to add a Texture to a Material using Python?