python-pptx throwing error on loading (2003 converted) 2010 powerpoint document in windows 7 64x ?

208 views Asked by At

I'm using python-pptx version 0.5.7 - Windows 7 64x. I'm not sure how to procedure as everything I was able to find online didn't work. I'm not sure why I get a zip file error since this is a powerpoint document.

As always thanks for the help.

>>> from pptx import Presentation
>>> f = open("Randy-Diehl-Analysis.pptx")
>>> prs = Presentation(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pptx\api.py", line 26, in __init__
    self._package = Package.open(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\package.py", line 44, in open
    return super(Package, cls).open(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\package.py", line 122, in open
    pkg_reader = PackageReader.from_file(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\pkgreader.py", line 32, in from_file
    phys_reader = PhysPkgReader(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\phys_pkg.py", line 102, in __init__
    self._zipf = ZipFile(pkg_file, 'r')
  File "C:\Python27\lib\zipfile.py", line 712, in __init__
    self._GetContents()
  File "C:\Python27\lib\zipfile.py", line 746, in _GetContents
    self._RealGetContents()
  File "C:\Python27\lib\zipfile.py", line 787, in _RealGetContents
    centdir = struct.unpack(structCentralDir, centdir)
struct.error: unpack requires a string argument of length 46
1

There are 1 answers

0
cph On BEST ANSWER

I needed to specify the read and write parameters to use that file.

f = open("Randy-Diehl-Analysis.pptx", "r+b")