Search code examples
pythonpypdf

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


I'm following the book 'Automate the boring stuff' and on chapter 15 I ran into a problem. It should be a very simple program to unlock a decrypted file using a password but it just won't work for me. I've looked up solutions to this problem. The solutions where to use the open function with 'rb' I did that but still get the same error. All help is appreciated!

import PyPDF2 

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

Error:

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

Solution

  • Duplicate of this post : UnsupportedOperation: can't do nonzero end-relative seeks : Python - PyPDF2

    Correct use is : pdfReader = PyPDF2.PdfFileReader(open('PATH_TO_PDF','rb'))

    You may have a new error if you encrypt your pdf with Acrobat6 (see reported issue in PyPDF2 github).