IndexError: invalid index to scalar variable

this is my code until the error occured :

import cv2
import numpy as np
import glob
import random
print(cv2.__version__)

# Load Yolo
net = cv2.dnn.readNet(r"C:\HALCON\PROJECTS\YOLO\yolo_custom_detection\yolov3_training_last.weights", r"C:\HALCON\PROJECTS\YOLO\yolo_custom_detection\yolov3_testing.cfg")

# Name custom object
classes = ["handle"]

# Images path
images_path = glob.glob(r"C:\HALCON\PROJECTS\YOLO\RightHandle1_images_YOLO\*.jpg")



layer_names = net.getLayerNames()
print(layer_names)
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]

my error :

Traceback (most recent call last):
  File "c:\HALCON\PROJECTS\YOLO\yolo_custom_detection\yolo_object_detection.py", line 20, in <module>
    output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
  File "c:\HALCON\PROJECTS\YOLO\yolo_custom_detection\yolo_object_detection.py", line 20, in <listcomp>
    output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
IndexError: invalid index to scalar variable.

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 !

I see, I tried and it works, thankyou so much !