'no placeholder on this slide with idx == 1

I tried to merge several ppt files within one folder and output it to one single file. The flowing is my code. It throws an error like this:

line 766, in __getitem__
    raise KeyError("no placeholder on this slide with idx == %d" % idx)
KeyError: 'no placeholder on this slide with idx == 1

My code:

import os
import glob
from pptx import Presentation

path = "/Users/User/Library/CloudStorage/OneDrive/"

pres = glob.glob(path+"*.pptx")
prs1 = Presentation(pres[0])

for presentation in pres[1:]:
    pres=Presentation(presentation)
    for slide in pres.slides:
        sl=prs1.slides.add_slide(prs1.slide_layouts[1])
        sl.shapes.title.text=slide.shapes.title.text
        try:
            sl.placeholders[1].text = slide.placeholders[1].text
        except:
            sl.placeholders[1].image = slide.placeholders[1].image
    prs1.save("all_together.pptx")



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source