Python Scripting : AttributeError : 'SpaceTextEditor ' object has no attribute 'context'
I am a big advocate of avoiding bpy.ops as much as possible.  I wrote an example at http://web.purplefrog.com/~thoth/blender/python-cookbook/load-image-texture.html which might help you understand how to use python to create a material using an image texture:

Here is the most important bit:

def material_for_texture(fname):
    img = bpy.data.images.load(fname)

    tex = bpy.data.textures.new(fname, 'IMAGE')
    tex.image = img

    mat = bpy.data.materials.new(fname)
    mat.texture_slots.add()
    ts = mat.texture_slots[0]
    ts.texture = tex
    ts.texture_coords = 'ORCO'

    return mat

fname = "/var/tmp/blender/mohawk-seal0001.png"
obj = bpy.context.active_object
mat = material_for_texture(fname)
if len(obj.data.materials)&lt;1:
    obj.data.materials.append(mat)
else:
    obj.data.materials[0] = mat