Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"file has not been decrypted" error #51

Closed
alisufian opened this issue Jan 7, 2014 · 11 comments
Closed

"file has not been decrypted" error #51

alisufian opened this issue Jan 7, 2014 · 11 comments

Comments

@alisufian
Copy link

Exception occurs when reading certain valid pdfs

File "/usr/local/lib/python2.7/dist-packages/PyPDF2/pdf.py", line 1019, in getObject
raise Exception, "file has not been decrypted"

PDF: http://dis.puc.state.oh.us/ViewImage.aspx?CMID=A1001001A13L20B64142B89320

@Rob1080
Copy link
Contributor

Rob1080 commented Jan 7, 2014

I think I had a similar issue. Can you try:

input = pyPdf.PdfFileReader(<your file>)
if input.isEncrypted:
    input.decrypt('')

This may be related to this issue outlined here:
https://bugs.launchpad.net/pypdf/+bug/355479

@alisufian
Copy link
Author

Great! It worked. Thank you. I should have researched a little more before filing a bug report.

elena pushed a commit to elena/PyPDF2 that referenced this issue Apr 30, 2015
Work around for PDFs which behave as if decrypted, though were 
encrypted without a password.
elena pushed a commit to elena/PyPDF2 that referenced this issue Apr 30, 2015
Work around for PDFs which behave as if decrypted, though were 
encrypted without a password.
mstamy2 added a commit that referenced this issue May 26, 2015
Fix "file has not been decrypted" error #51.
@lukasz-virtualo
Copy link

I am using the trick:

if input.isEncrypted:
input.decrypt('')

However, some PDFs crash the script with the following traceback:

Traceback (most recent call last):
File "scripts/wm_add_page_pdf.py", line 85, in
if not input_pdf.decrypt(''): # try empty pass
File "/usr/lib/pymodules/python2.7/pyPdf/pdf.py", line 897, in decrypt
return self._decrypt(password)
File "/usr/lib/pymodules/python2.7/pyPdf/pdf.py", line 907, in _decrypt
user_password, key = self._authenticateUserPassword(password)
File "/usr/lib/pymodules/python2.7/pyPdf/pdf.py", line 948, in _authenticateUserPassword
encrypt.get("/EncryptMetadata", BooleanObject(False)).getObject())
File "/usr/lib/pymodules/python2.7/pyPdf/pdf.py", line 1821, in _alg35
key = _alg32(password, rev, keylen, owner_entry, p_entry, id1_entry)
File "/usr/lib/pymodules/python2.7/pyPdf/pdf.py", line 1732, in _alg32
m.update(id1_entry)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128)

This is not normal, I would expect a return value from decrypt(), not an exception...

@lukasz-virtualo
Copy link

To clarify I'm using version pyPdf==1.13

Yanok35 added a commit to Yanok35/ebookonline that referenced this issue Sep 16, 2016
workaround applied as described below:
py-pdf/pypdf#51
https://bugs.launchpad.net/pypdf/+bug/355479

Signed-off-by: Yannick Gicquel <ygicquel@gmail.com>
@istommao
Copy link

istommao commented Jul 4, 2018

input.decrypt('')
raise
NotImplementedError: only algorithm code 1 and 2 are supported

PyPDF2==1.26.0

@elmar-hinz
Copy link

input = pyPdf.PdfFileReader(<your file>)
if input.isEncrypted:
    input.decrypt('')

This works for me. Surprisingly I don't need it, when I run my script in the debugger step by step.

Maybe this works in the sense of a sleep function.

@TrendMend
Copy link

@istommao did you ever find a solution? I am having the same issue.

@javiermarcon
Copy link

I have the same error, when I try to read an unencrypted file. If I try to run input.decrypt(''), I get the error NotImplementedError: only algorithm code 1 and 2 are supported

polyglot-jones pushed a commit to polyglot-jones/PyPDF2 that referenced this issue Aug 11, 2020
@Hussam1
Copy link

Hussam1 commented Feb 2, 2021

I am having the issue I am reading an unencrypted file. If I try to run input.decrypt(''), I get the error NotImplementedError: only algorithm code 1 and 2 are supported

@DrameMariama
Copy link

@Hussam1 were you able to find a solution? I'm facing the same issue.

@FoldedPanda
Copy link

FoldedPanda commented May 18, 2021

I think I solve the issue. I unlocked the pdf using: https://smallpdf.com/unlock-pdf

However, when I run
pdf_reader.getFields() I get some pretty weird stuff.

Not sure if it has anything to do with this or if the pdf was just poorly made from the start.

--Edit

I was using the wrong method, I really wanted .getFormTextFields(), and it worked just fine, so this really did do the trick for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants