your code is outdated
handling of std::vector in python changed with 4.6.0
(there is no more “additional vector dimension”)
either use
layer_names[i - 1]
or, better, avoid the confusion and use
output_layers = net.getUnconnectedOutLayersNames()
like it is in the official sample !