2.80 nla.bake - returns 'Nothing to bake' - when selecting bones through script
(Question duplicated from blenderartists.org. I answered it there, and am copying my answer here.)

I’ve seen that “Nothing to bake” error in 2.80 when another object is selected in addition to the armature. Try deselecting everything in Object mode, selecting the armature, re-entering Pose mode, then baking. Here is a code snippet that works for me:

scene = bpy.data.scenes[0]
arm   = bpy.data.objects['metarig']

# ensure that only the armature is selected in Object mode
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
arm.select_set(True)
scene.view_layers[0].objects.active = arm

# enter pose mode and bake
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.pose.select_all(action='SELECT')
bpy.ops.nla.bake(frame_start=0, frame_end=10, step=1, only_selected=True,
                    visual_keying=True, clear_constraints=True, clear_parents=False,
                    use_current_action=True, bake_types={'POSE'})
```