Index Error: bpy_prop_collection[index]: index 0 out of range, size 0 So, here's the code i'm trying to implement:

import bpy

#remember to bpy.ops.mesh.quads_convert_to_tris()

ob = bpy.data.objects

#create an output file
import os
file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')


for objects in ob:
    #get vertices, normals, and texCoords
    if(ob[objects.name].type == 'MESH'):
        for face in ob[objects.name].data.polygons:
            for vert, loop in zip(face.vertices, face.loop_indices):
                coord = ob[objects.name].data.vertices[vert].co
                normal = ob[objects.name].data.vertices[vert].normal
                layers = ob[objects.name].data.uv_layers
                for MeshUVLoopLayer in layers:
                    #the problem is here
                    uv = ob[objects.name].data.uv_layers[MeshUVLoopLayer.name].data[loop].uv
                    file.write("v {co.x} {co.y} {co.z}\nvn {n.x} {n.y} {n.z}\nvt {uv.x} {uv.y}\n".format(co=coord, n=normal, uv=uv))


this was working when i wasn't doing the for loop and it was '...uv_layers.active', but when i replaced it with what it is now i get this error. 

i know the bpy_prop_collection isn't empty it should have two items in it and i checked it with the console using bpy.data.objects["Suzanne"].data.uv_layers.items() and it came out with UVMap and UVMap.001. Suzanne is the only object in the scene, plus it checks the objects first if they're meshes.

Any ideas, on what's causing the error? Or what i'm obviously doing wrong, but am completely oblivious to?
You need to run the script in Object Mode, make sure that you meet all requirements (material and unwrapping) read the bullet points here,