Skip to content

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

@shoang22

Description

@shoang22
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 #929.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions