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)