Simple python script to stitch images into movie failing with incorrect context
Ditch the operator.
Have updated the code from
Importing multiple movie clips inside one directory via script

look at all images in a path
glob on &quot;*.png&quot;
to use pathlib.Path

Adding each image as a strip.
import bpy
from pathlib import Path

# glob all movie files from
dir_path = &quot;/home/batfinger/Pictures&quot;
img_dir = Path(dir_path)
glob = &quot;*.png&quot;
frame_duration = 24
files = sorted(list(img_dir.glob(glob)))

# get sequence editor
scene = bpy.context.scene
#scene.sequence_editor_clear()
sed = scene.sequence_editor_create()
seq = sed.sequences

# add movie strips
for i, fp in enumerate(files):
    ms = seq.new_image(
            name=fp.name,
            filepath=str(fp),
            channel=i + 1,
            frame_start= i * frame_duration + 1 ,
            
            )
    ms.frame_final_duration = frame_duration
    # print some details
    print(&quot;%s ch: %d fs: %3.1f len: %d&quot; %
            (fp.name, i + 1, ms.frame_start, ms.frame_final_duration)
            )

Adding images as sequence to one strip.
import bpy
from pathlib import Path

dir_path = &quot;/home/batfinger/Pictures&quot;
img_dir = Path(dir_path)
glob = &quot;*.png&quot;
frame_duration = 24
files = sorted(list(img_dir.glob(glob)))

# get sequence editor
scene = bpy.context.scene
#scene.sequence_editor_clear()
sed = scene.sequence_editor_create()
seq = sed.sequences
duration = len(files)
# add image strip using first
fp = files.pop(0)
imstrip = seq.new_image(
    name=fp.name,
    filepath=str(fp),
    frame_start=1,
    channel=1,
    )
# add the elements 
while files:
    imstrip.elements.append(files.pop(0).name)
    
imstrip.frame_final_duration = duration
imstrip.update()