TwistedTwigleg, if I understand you correctly, your idea is this one, right?
if Vector3(0, 1, 0).cross(bo - midpoint(ao, bo)) != Vector3():
$connection.look_at(bo, Vector3(0, 1, 0))
$connection.rotate_object_local(Vector3(1,0,0), -PI/2)
Sometimes I still get incorrect results. Instead, I did a hack, where I do the same check, but I also update the target vector:
if Vector3(0, 1, 0).cross(bo - midpoint(ao, bo)) == Vector3():
$connection.look_at(bo + Vector3(0.0, 0.0, 0.0001), Vector3(0, 1, 0))
else:
$connection.look_at(bo, Vector3(0, 1, 0))
$connection.rotate_object_local(Vector3(1,0,0), -PI/2)
While it feels like a terrible solution, it works in each case.