Cannot apply modifier via script despite object being active?
bpy.ops.object.modifier_apply(modifier='Mirror')


This command requires you to give it a modifier name.

bpy.ops.object.apply_all_modifiers()


This will apply all modifiers.  Note, this is a operator from addon 'Modifier Tools'.  You have to have this addon enabled to be able to use that command.