Fill Mesh Holes Problem

I have a python script which identifies the naked edges of a mesh and stores them as polylines. From there, I want to fill the holes. But the problem is my script is only repairing one hole. Any idea why this is happening?

To the left below is the mesh before fixing. The right picture shows one of the holes to be prepared, but the other one remains open. (851.7 KB)