python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

AttributeError: 'Part' object has no attribute 'image'

Open shoang22 opened this issue 4 months ago • 0 comments

async def read_pptx(f: io.BytesIO, client: AioBaseClient | AsyncClient) -> list[str]:
    presentation = pptx.Presentation(f)
    text = []
    for slide in presentation.slides:
        page = []
        for shape in slide.shapes:
            if hasattr(shape, "text_frame"):
                page.append(shape.text_frame.text)
            elif shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
                img = io.BytesIO(shape.image.blob)
readers.py:395: in read_pptx
    img = io.BytesIO(shape.image.blob)
.venv/lib/python3.12/site-packages/pptx/shapes/picture.py:190: in image
    return slide_part.get_image(rId)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pptx.parts.slide.SlidePart object at 0x17b840a10>, rId = 'rId2'

    def get_image(self, rId: str) -> Image:
        """Return an |Image| object containing the image related to this slide by *rId*.
    
        Raises |KeyError| if no image is related by that id, which would generally indicate a
        corrupted .pptx file.
        """
>       return cast("ImagePart", self.related_part(rId)).image
E       AttributeError: 'Part' object has no attribute 'image'

.venv/lib/python3.12/site-packages/pptx/parts/slide.py:41: AttributeError

When I convert the file to a .zip and extract the images, I see that the file is a .tif. Seems similar to https://github.com/scanny/python-pptx/issues/929.

shoang22 avatar Sep 02 '25 17:09 shoang22