Need help with creating a rigging script

So I have a skeleton and I used a ‘CHILD OF’ bone constraint to a bone to make it retain its translation with respect to another bone in the same armature. I needed to export this animation so I wanted to convert the constrained bone positions into keyframes. I wrote a looping script for this:

import bpy

for[“v_pist_usp.qc”].frame_current in range([“v_pist_usp.qc”].frame_start,[“v_pist_usp.qc”].frame_end):

bpy.ops.pose.contraint_add(type='CHILD_OF')["v_pist_usp.qc_skeleton"].pose.bones["j_mag1"].constraints["Child Of"].target=v_pist_usp.qc_skeleton["v_pist_usp.qc_skeleton"].pose.bones["j_mag1"].constraints["Child Of"].subtarget=j_slide


But It shows error on first line for disabling constraint influence(even though I do have the constraint setup to begin with). Error message:
“RuntimeError: Operator bpy.ops.constraint.disable_keep_transform.poll() failed, context is incorrect”

Things I have tried: Removed the line and decided to execute it without a loop and manually disable influence on reach execution; blender crashed each time I attempted executing.

Expected behaviour: The script sets up the constraint, disables/applies influence and keyframes it, deletes the constraint, sets up the constraint again, moves to next keyframe.

N.B: The rest of the armature has keyframed motion. I wanted a single unkeyframed bone(driven by constraint) to follow the keyframed one and get keyframed throughout its motion. Thus becoming suitable for exporting.