如何解决 io.UnsupportedOperation: 无法进行非零端相对查找?

How do I solve io.UnsupportedOperation: can't do nonzero end-relative seeks?

我正在学习这本书 'Automate the boring stuff' 并且在第 15 章我 运行 遇到了一个问题。使用密码解锁解密文件应该是一个非常简单的程序,但它对我不起作用。我已经查找了解决此问题的方法。在 'rb' 中使用 open 函数的解决方案 我这样做了,但仍然出现相同的错误。感谢所有帮助!

import PyPDF2 

pdfReader = PyPDF2.PdfFileReader(open('C:\Path\to\the\file\encrypted.pdf'),'rb')
pdfReader.decrypt('rosebud')

错误:

io.UnsupportedOperation: can't do nonzero end-relative seeks

此 post 的副本:UnsupportedOperation: can't do nonzero end-relative seeks : Python - PyPDF2

正确的用法是:pdfReader = PyPDF2.PdfFileReader(open('PATH_TO_PDF','rb'))

如果您使用 Acrobat6 (see reported issue in PyPDF2 github) 加密您的 pdf,您可能会遇到新的错误。