You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行PDF拆分脚本时遇TypeError: __init__() got unexpected keyword argument 'strict'

Fixing "TypeError: init() got an unexpected keyword argument 'strict'" in Your PDF Splitting Script

Hey there, let's get this sorted out for you. That error you're hitting almost always boils down to a version mismatch between the PDF processing library your script is using (I'd bet it's PyPDF2, since this is super common with that tool) and the code you've written.

What's causing this?

The strict keyword argument was used in older versions of PyPDF2 to control how the library handles malformed PDFs. But starting with PyPDF2 v2.0+, this parameter was removed entirely. So if:

  • You're running an older script that uses strict with a newer PyPDF2 version, or
  • You've installed a newer library but your code is written for an older release, you'll hit this exact error.

Step-by-step fixes:

  1. First, confirm your library and version
    Check your script's import statements—look for lines like import PyPDF2 or from PyPDF2 import PdfReader. Then run this command in your terminal to check the installed version:

    pip show PyPDF2
    
  2. Adjust based on your version

    • If you have PyPDF2 v2.0 or newer:
      Go to line 115 of your script (where the error is triggering) and remove the strict keyword argument entirely. For example, if your code looks like this:
      reader = PyPDF2.PdfReader("your_file.pdf", strict=False)
      
      Change it to:
      reader = PyPDF2.PdfReader("your_file.pdf")
      
    • If you have an older PyPDF2 version (pre-2.0) but need the strict parameter:
      Upgrade to the latest stable version to avoid other compatibility issues:
      pip install --upgrade PyPDF2
      
      Then remove the strict argument as above, since it's no longer supported.
  3. If it's not PyPDF2
    If you're using a different PDF library (like pdfplumber or another tool), the same logic applies: check the library's latest docs to see if the strict parameter was deprecated or renamed, then adjust your code accordingly.

Quick check

Double-check line 115 of your 3. Split Invoice & SuppDocs.py file—this is where you're initializing the PDF reader, and that's where the strict argument is hiding that's causing the conflict.

内容的提问来源于stack exchange,提问作者Harry Adkins

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:20:33