Armature not in edit mode
It's more reliable to tell Blender which mode to switch to instead of relying on editmode_toggle(), because there's an enter editmode option, so you can't be sure what mode an object is in after creation:

bpy.ops.object.mode_set(mode='EDIT')


BTW: this is better than your current code:

try:
    armature = bpy.data.objects[armature_name]
except KeyError:
    # create armature