Index Error: bpy_prop_collection[index]: index 0 out of range, size 0
You need to run the script in Object Mode, make sure that you meet all requirements (material and unwrapping) read the bullet points here,