TypeError: __init__() got an unexpected keyword argument 'strict'

岁酱吖の 提交于 2021-01-28 11:56:36

问题


I am getting an error when trying to run my script. The purpose of my script is to split PDFs based on the bookmarks given to them and move them into specific folders.

However I'm getting this error when trying to read the PDF.

Traceback (most recent call last):
  File "I:\Harry\[Scripts]\013 - [Blackstone Changes]\3. Split Invoice & SuppDocs.py", line 280, in <module>
    split(path, filename)
  File "I:\Harry\[Scripts]\013 - [Blackstone Changes]\3. Split Invoice & SuppDocs.py", line 115, in split
    pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)
TypeError: __init__() got an unexpected keyword argument 'strict'

This is my code:

  def split(path, filename):
     idx = 1

     name_fmt = 'CD_%s_%s.pdf'

with open('+Split.csv', 'ab') as fout:
    writer = csv.writer(fout)

    print os.path.join(path, filename)
    pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)

    filename_no_ext, ext = os.path.splitext(filename)

    invoice_folder = os.path.join('+Renamed', 'Invoice')
    sdoc_folder = os.path.join('+Renamed', 'Supporting Docs')


    try:
        os.makedirs(invoice_folder)
    except OSError:
        pass

    try:
        os.makedirs(sdoc_folder)
    except OSError:
        pass

    bookmark_list = list(bookmarks(pdf))

    if not bookmark_list:
        print '\t ->', os.path.join(invoice_folder, filename)
        shutil.copy(
            os.path.join(path, filename),
            os.path.join(invoice_folder, filename)
            )
        return


    errors = find_errors(bookmark_list)
    if errors:
        print >>sys.stderr, os.path.join(path, filename)
        for error in errors:
            print >>sys.stderr, error
        print >>sys.stderr
        return

Does anyone have any ideas on ANYTHING that might be able to help me? Also I'm new to Python so try and dumb it down for me! Thanks!


回答1:


Likely cause is based on the error you stated

pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'), strict=False)

this line shouldn't function doesn't allow the value strict so it should be removed or used elsewhere. For example

pdf = pyPdf.PdfFileReader(open(os.path.join(path, filename), 'rb'))


来源:https://stackoverflow.com/questions/49939282/typeerror-init-got-an-unexpected-keyword-argument-strict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!