How do you manipulate pose bones using python? I'm trying to render different images of hand gestures using python, but for some reason, I'm unable to get the hand armature bones to move. I'm using Manuel Bastoni for the model. http://www.manuelbastioni.com/

Here's the code that I have right now: 

bpy.ops.object.mode_set(mode='POSE')
for bone in bones:
    x = bone.location[0] + random.uniform(-0.2, 0.2)
    y = bone.location[1] + random.uniform(-0.2, 0.2)
    z = bone.location[2] + random.uniform(-0.2, 0.2)
    bone.location[0] = x
    bone.location[1] = y
    bone.location[2] = z
    bpy.context.scene.update()
bpy.context.scene.render.filepath = outfile_name
bpy.ops.render.render(write_still=True)


I saw that in the python console, bone.location = (x, y, z) works perfectly fine to manipulate the bones, but it's not working here. 

Please let me know what I can do to manipulate the pose bones through a python script!

Thanks!
I'd avoid using ops to set the mode to Pose Mode.

Access the bones directly through the hierarchy as it is exposed through the api.

import bpy
import random

armature = bpy.context.scene.objects['Armature']

for pose_bone in armature.pose.bones:
    x = pose_bone.location[0] + random.uniform(-0.2, 0.2)
    y = pose_bone.location[1] + random.uniform(-0.2, 0.2)
    z = pose_bone.location[2] + random.uniform(-0.2, 0.2)
    pose_bone.location[0] = x
    pose_bone.location[1] = y
    pose_bone.location[2] = z